Jump to content
ChetanaSforum
Sign in to follow this  
Najma Sultana

plz explain the usage and importance of 'exists' command in SQL

Recommended Posts

Hi friends, can anyone explain me how to use exists command and the context where we can use this command. Plz explain with the help of an example.

Share this post


Link to post
Share on other sites

hi friend,

Exists commands just like a equals that means, it checks with the inner queries ; wheter the inner queries is rit then it pass through correspoding fields i will give the example.

 

 

select * from student where sid exists(select * from sid,rid from student,register where student.sid=register.rid);

 

if the inner that means sid and register's rid is equals then the corresponding sid's data(fields) are displayed.

 

 

:) pk bye by

jaikumar

Share this post


Link to post
Share on other sites

another simple example:

 

The following example list all the departments for which there is at least one employee in that department has salary exceeds 500000.

 

SELECT Dept_Name FROM Department d WHERE EXISTS (SELECT Dept_Id FROM EMPLOYEE e WHERE e.Salary > 500000 AND d.Dept_Id = e.Dept_Id)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×