QAds
Samsung I7500 Android 5 MP Camera, Wi-Fi, and 8 GB Memory
$599.99
Nikon D3000 10.2MP Digital SLR Camera with 18-55mm f/3.5-5.6G AF-S DX VR Nikkor Zoom Lens
$337.50
Apple iPod shuffle 4 GB Mavi
$49.13
Toshiba Satellite T115D-S1125 LED TruBrite Laptop
$360.00
:: HOME MySQL EXISTS and NOT EXISTS Function
 
EXISTS and NOT EXISTS Function

If you want to get data (rows) from a table which are not in other table:

For example, You have two tables, table1 and table2. You want to get data in table1 which are not in table2  . there is a common field that common field that id. Then you need to use such query:

SELECT  * FROM table1 WHERE NOT EXISTS (SELECT id FROM table2 WHERE table1.id=table2.id);

If you want to reverse, data from table1 which are also in table2.

SELECT  * FROM table1 WHERE EXISTS (SELECT id FROM table2 WHERE table1.id=table2.id);

 

this is same with general sql query :

 

SELECT * FROM table1, table2 WHERE table1.id = table2.id;