View Full Version : How to get data using single select query

07-12-2011, 08:19 PM
I'm created two table first one is test1 and second one is test2.
In first table one field is id and in second table one field is id.
in first table two data/value insert 1 and 2 and second table four data/value insert 1, 2, 3 and 4

I want to access only 3 and 4 data with use join key

Is this possible to get data using single select query.

Old Pedant
07-12-2011, 10:40 PM
SELECT table2.*
FROM table2 LEFT JOIN table1 ON table2.id = table1.id
WHERE table1.id IS NULL

But you might find it easier to think of if you do it this way:

FROM table2
WHERE id NOT IN ( SELECT id FROM table1 )

The two queries really do the same thing.