On Tue, Sep 8, 2009 at 12:31 AM, Dennis Volodomanov<denn...@conceiva.com> wrote:
> Hello all,
>
> A small SQL problem, no doubt, for experts here.
>
> Let's say we've got 4 tables:
>
> CREATE TABLE TABLEA ( ID INTEGER PRIMARY KEY, IDB INTEGER, IDC INTEGER, IDD 
> INTEGER );
> CREATE TABLE TABLEB ( ID INTEGER PRIMARY KEY, DATA );
> CREATE TABLE TABLEC ( ID INTEGER PRIMARY KEY, DATA );
> CREATE TABLE TABLED ( ID INTEGER PRIMARY KEY, DATA );
>
> What I'm trying to achieve is something like the following:
>
> SELECT * FROM TABLEB WHERE ID IN ( SELECT IDB AS ID FROM TABLEA LEFT JOIN 
> TABLEB ON IDB=1 )
>

The above statement doesn't make any sense. In your sub-select, you
are JOINing TABLEA to TABLEB, but you are not specifying the columns
on which to JOIN. You have to do like so...

TABLEA LEFT JOIN TABLEB ON TABLEA.some_column = TABLEB.some_column

then you can specify a WHERE clause for IDB = 1, but then, your query
doesn't make any sense.

> But I also need to add additional constraints from TABLEC and TABLED to 
> narrow down the results. Basically, I only want results from TABLEA with a 
> given set of IDB, IDC and IDD (there could be multiple of each of course).
>

Now things get even more confusing. You want results from TABLEA, so
you have to have

SELECT * FROM TABLEA
WHERE IDB IN (...) AND IDC IN (...) AND IDD IN (...)

(replace AND in the above statement with OR to get a bigger set back)

> Can you please help me out - any hints are greatly appreciated!

It would help to restate the problem more clearly, perhaps with some
example data, so the relationship between TABLEA and the other tables
is more clear.


>
> Thank you in advance,
>
>   Dennis
>
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>



-- 
Puneet Kishor
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to