sql server - SQL - Return all rows for ID where one row meets condition A,B,or C -
i'm trying return rows particular ids condition met in 1 of rows tied ids. pardon me being newbie sql... example below:
id * line * # *
12 * 1 * *
- 12 * 2 * b *
- 12 * 3 * x *
- 12 * 4 * y *
- 15 * 1 * *
- 15 * 2 * b *
- 15 * 3 * c *
not sure code other select , condition = (x, y, or z) return:
id * line * # *
12 * 1 * * <-- doesn't include x, y, or z part of id which
- 12 * 2 * b * <-- has x in row of id
- 12 * 3 * x *
- 12 * 4 * y *
i'm wanting pull row records despite not meeting condition long they're part of id has row meets condition.
thanks help!
* edit: including code attempted*
select id ,line ,# id, in ( select id # in ('x','y','z')) results:
id line # 12 3 x 12 4 y what need:
id line # 12 1 12 2 b 12 3 x 12 4 y i feel need create temp table of id & line using condition of in('x','y','z') , inner join on id line(s) not x,y,z. think may work, haven't learned how use temp tables yet. i'm little troubled because i'm using query, i've simplified ton here, i'm selecting 18 fields join in 7 other tables. think complicating understanding of subquery, not subquery being affected that.
thanks , answers far!
you can use subquery , in this.
select * yourtable id in (select id yourtable # in ('x','y','z')) just note, there no 12 * 4 * c * in data think it's type-o in results , should 12 * 4 * y *
Comments
Post a Comment