On Wed, 18 Mar 2009 16:04:51 +0000, Dermot
<paik...@googlemail.com> wrote:

>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');

subselect
(If there's more than one 'Joe', only the first 'Joe' is
used)

>> this is better:
>> select tbl1.* from tbl1, tbl2
>> where tbl1.description='someval'
>> AND tbl2.name='Joe' and tbl2.id=tbl1.foreign_key_id;

implicit join
In this case you could also write:
SELECT tbl1.*
  FROM tbl1 
 INNER JOIN tbl2
    ON tbl2.id=tbl1.foreign_key_id
 WHERE tbl1.description='someval'
   AND tbl2.name='Joe';

which is an explicit join.

>> 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');

'IN subselect set' (I'm making this one up).

>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?

See above.

>Thanx,
>Dp.

HTH
-- 
  (  Kees Nuyt
  )
c[_]
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to