SQL IN operator

IN operator uses to specify one or more values in where clause.

Syntax:

select columns from table_name where column_name IN ( values )

Examples:- 

Consider below EMP table structure

EmpnoEmpnameSalaryDeptno
10Bill120005
11Solomon100005
12Susan100005
13Wendy90001
14Benjamin75001
15Tom76001
16Henry85002
17Robert95002
18Paul77002

1. Find all details of Bill, Solomon and Wendy employee. 

Select * from EMP where empname IN'Bill' , 'Solomon' ,'Wendy');

2. Find details of employee earning highest salary.

Select * from EMP where salary IN (select max(salary) from EMP) ;

3. Find details of employees earning less than highest salary.

Select * from EMP where salary NOT IN (select max(salary) from EMP) ;  

Not that NOT IN operator is a negation of IN operator. 

No comments:

Post a Comment