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

-----Original Message-----
From: sqlite-users-boun...@sqlite.org
[mailto:sqlite-users-boun...@sqlite.org] On Behalf Of Dermot
Sent: Wednesday, March 18, 2009 11:47 AM
To: General Discussion of SQLite Database
Subject: Re: [sqlite] Newbie question

2009/3/18 Igor Tandetnik <itandet...@mvps.org>:
> Dermot <paik...@googlemail.com> wrote:
>> I want to do a select query a bit like this:
>>
>> SELECT * FROM tbl1 WHERE description="someval" AND
>> foreign_key_id=(select id from tbl2 where name="Joe");
>>
>> This gives me a syntax error and my other efforts are not yielding
>> results.
>
> What's the text of the error message?




SELECT * FROM tbl1 WHERE description="someval" AND
foreign_key_id=(select id from tbl2 where name="Joe");

This attempt give the error:

SQL error: near "=": syntax error

SELECT * FROM tbl1 WHERE description="someval" AND
foreign_key_id='select id from tbl2 where name="Joe"';

This return nothing, although it should. If I break the queries into 2
separate select statements they verify.

This is SQLite 3.5.1.

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

Reply via email to