Another Numpty SQL Question
Author
Discussion

mystomachehurts

Original Poster:

11,669 posts

281 months

Wednesday 10th October 2007
quotequote all
Hoping someone can help with this.
Cosider the following table, if a query is run that selects one row in the table

e.g. select * from table where f1='a' I get row 1

what is the a way to also return all the rows that share the same frame number?

so if I did select * from table where f1='f' I want get rows 1,2 & 3.

and if I did select * from table where f1='x' I want get rows 1,2,3,4,5 & 6.

I'm sure it's something very simple
Many thanks




id frame type f1
1 1 1 a
2 1 2 f
3 1 3 x
4 2 1 x
5 2 2 e
6 2 3 l


LeoSayer

7,866 posts

275 months

Wednesday 10th October 2007
quotequote all
Select * from table
Where type in
(Select type from table
Where f1 = a)


Edited by LeoSayer on Wednesday 10th October 12:52

GHW

1,294 posts

252 months

Wednesday 10th October 2007
quotequote all
You need a subquery.

SELECT * FROM table WHERE frame IN (SELECT frame FROM table WHERE f1='x');


mystomachehurts

Original Poster:

11,669 posts

281 months

Wednesday 10th October 2007
quotequote all
Thanks people!

I thought it should be super easy!