DEV Community

vidhya murali
vidhya murali

Posted on

PostgreSQL Operators

select * from employee
where salary >30000

select * from employee
where salary < 30000

select * from employee
where salary=40000

select * from employee
where salary >=35000

select * from employee
where age <= 25

select * from employee
where department != 'IT'  ---or <>
Enter fullscreen mode Exit fullscreen mode

** AND , OR**

select * from employee
where department='IT' and salary>30000

select * from employee
where department='IT' or department='Finance'

select * from employee
where city='Chennai' and salary>30000

select * from employee
where city!='Chennai'

select * from employee
where  salary>30000 and age<30

select * from employee
where department='IT' or salary>45000

Enter fullscreen mode Exit fullscreen mode

BETWEEN

select * from employee
where salary between 30000 and 40000

select * from employee
where age between 25 and 30

select * from employee
where salary not between 30000 and 40000
Enter fullscreen mode Exit fullscreen mode

IN , NOT IN

select * from employee
where department in ('IT','HR','Finance')

select * from employee
where city in ('chennai','bangalore')

select * from employee
where department not in ('HR', 'Finance')
Enter fullscreen mode Exit fullscreen mode

Like

remember :

  • % → zero or more characters
  • _ → exactly one character
select * from employee
where employee_name like 'v%'

select * from employee
where employee_name like '%a'

select * from employee
where employee_name like '_a%'


select * from employee
where employee_name like '_i%'
Enter fullscreen mode Exit fullscreen mode

NUll

select * from employee
where city is Null

select * from employee
where city is not Null
Enter fullscreen mode Exit fullscreen mode
select * 
from employee
where city='Chennai;
 and department in ('HR','IT')

select * from employee
where salary>30000 and department!='IT'

select * from employee
where city in ('Chennai','Bangalore') and salary>30000

select * from employee
where salary between 30000 and 50000
 and department='IT'

select * 
from employee
where department in ('IT','Finance') and 
salary >40000

select * from employee
where salary>=30000 and age<30
 and department in ('IT','HR')
and city!='mumbai'
Enter fullscreen mode Exit fullscreen mode

Top comments (0)