Click to See Complete Forum and Search --> : Help with select where


rayhab
08-17-2007, 03:58 PM
Hi, i couldn't find this solution anywhere on the forums. Haven't worked with sql in awhile and can't figure it out.


SELECT * FROM table1 where id = (SELECT id FROM table2 t2 WHERE t2='1') ORDER BY thedate DESC LIMIT 10

Basically, i want this statement to work for multiple id's.
So i want to select from table1 based on multiple id's returned by the subquery, but it only works if there if one id. I'm assuming id use "where in" somehow, but now sure how to use it.

Ideas?

Of course right when i post i find the solution.
Here it is for others with the same problem.. it's simple.


SELECT * FROM table1 where id in (SELECT id FROM table2 t2 WHERE t2='1') ORDER BY thedate DESC LIMIT 10

TJ111
08-17-2007, 04:04 PM
Try this: http://www.w3schools.com/sql/sql_join.asp