In the first query the (select id from tbl2 where name='Joe') is referred to as a SUBQUERY.
The second query is uses a JOIN because you are joining together data from different rows. -Jeff -----Original Message----- From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-boun...@sqlite.org] On Behalf Of Dermot Sent: Wednesday, March 18, 2009 12:05 PM To: General Discussion of SQLite Database Subject: Re: [sqlite] Newbie question 2009/3/18 Hoover, Jeffrey <jhoo...@jcvi.org>: > > Assumming this is only one row in tbl2 where name='Joe'... > > this should work: > SELECT * FROM tbl1 > WHERE description='someval' > AND foreign_key_id=(select id from tbl2 where name='Joe'); > > this is better: > select tbl1.* from tbl1, tbl2 > where tbl1.description='someval' > AND tbl2.name='Joe' and tbl2.id=tbl1. foreign_key_id; > > if there may be many rows in tbl2 where name =- 'Joe' then > SELECT * FROM tbl1 > WHERE description='someval' > AND foreign_key_id in (select id from tbl2 where name='Joe'); Both of the top 2 worked. Thank you. I'll try and stick to the less ambiguous form and bear in mind all the comments about single quotes. A bit more information though. Is there a term for that type of SELECT statement? Thanx, Dp. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users