Home Sql Mysql-example Mysql Exists

Related Tutorials


 
 

Share on Google+Share on Google+

Mysql Exists

Advertisement
The Tutorial covers on 'Mysql Exists'. The section helps you to understand an example from 'Mysql Exists'.

Mysql Exists

     

The Tutorial covers on 'Mysql Exists'. The section helps you to understand an example from 'Mysql Exists'.We create a table 'stu' and 'Lib' with required filednames and datatypes  respectively.

 

 

 

 

 

Create Table Stu

Create Table Stu(Id int,Name Varchar(15));

Create Table Lib

Create Table Lib(Id int,libno int);

Insert Values into Stu

The insert into is used to add the records or rows to the table 'Stu'.

Insert Into Stu values(1,'Ajay');
Insert Into Stu values(2,'Bhanu');
Insert Into Stu values(4,'Rakesh');
Insert Into Stu values(5,'Santosh');
Insert Into Stu values(3,'Komal');

Insert Values into Lib

The insert into statement adds the records to the table 'Lib'.

Insert Into Lib values(1,101);
Insert Into Lib values(2,102);
Insert Into Lib values(4,103);
Insert Into Lib values(5,104);
Insert Into Lib values(3,105);

Query for Exists

The Query Exists returns only those id  records or rows that exists in table 'stu' and not in table 'lib'.

select id from stu where  EXISTS (select id from lib);

Result

+------+---------+
| Id   | Name    |
+------+---------+
| 1    | Ajay    |
| 2    | Bhanu   |
| 4    | Rakesh  |
| 5    | Santosh |
| 3    | Komal   |
+------+---------+

 

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 17, 2009

Related Tutorials

Discuss: Mysql Exists  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com