Queries/joins with more than 2 tables

M

martlaco1

Trying to..: find all IDNumbers from one table that are not in EITHER
of TWO other tables. Doing one is no sweat, via a left join. Tried
adding a second left join, but doesn't get the right results. Is there
a statement in SQL I can throw in to get the job done, or am I looking
at 2 separate queries?

To clarify, here's an example with simplified data, where yes or no
indicates the presence or absence of the given Idnumber:
IDNUMBER(from TableA) TABLE B TABLE C
1 yes no
2 no yes
3 no no

The only record I'd want is #3.

Thanks
Martin Lacoste
 
F

fmselcuk

Martin,

You may use the following sample to find out differences between more
than one table. Key point is using IN word in SQL command.

Regards.

Sample:
Select TA.ID From TA
Where TA.ID Not In (Select ID From TB) And TA.ID Not In (Select ID From
TC)
 
G

Gary Walter

Hi Martin,

I didn't test, but would have thought
the following would have worked...
(of course I could be wrong...)

SELECT
A.AID
FROM
(A LEFT JOIN B ON A.AID = B.BID)
LEFT JOIN C ON A.AID = C.CID
WHERE
B.BID IS NULL
AND
C.CID IS NULL;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top