QAds
12 Ay Taksit
Apple iPad 32gb Wi-Fi
$378.62
Apple iPad 64gb Wi-Fi 3G
$537.24
Apple iPod shuffle 2 GB Pink
$28.44
Sony VAIO VPC-CW21FX/P Laptop
$426.71
:: 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;

 


MySQL EXISTS and NOT EXISTS Function MySQL EXISTS and NOT EXISTS Function MySQL EXISTS and NOT EXISTS Function
MySQL EXISTS and NOT EXISTS Function
NEW QUESTION
 
Your E-Mail Address
»
Your e-mail will never be shown!  
   
 
Question
»
Please type your question and please use [CODE] tag for your codes!  
  Add CODE Quote BOLD ITALIC Underline Align Left Align Center Align Right Add Line  
   
 
Human Check
»
Enter human check code below!  
   
 
       
 
* Your Question will be answered as soon as possible, probably within 24 hours!
MySQL EXISTS and NOT EXISTS Function MySQL EXISTS and NOT EXISTS Function MySQL EXISTS and NOT EXISTS Function
MySQL EXISTS and NOT EXISTS Function
 
Website Designer, Search Engine Optimization Expert, Ajax Developer,Developed And Designed By Mumin Celik With Using PHP, MySQL, CSS, JavaScript, Ajax And Search Engine Optimizer Sinema ve Film Rehberi Sudoku Oyunu