AND OR condition in PostgreSQL

PostgreSQL AND OR To filter the results, the PostgreSQL AND and OR conditions can also be used in combination with SELECT, INSERT, UPDATE and DELETE statements to test more than one conditions.

Syntax:

WHERE condition_1
AND condition_2
..
OR condition_n;

Parameters: condition_1, condition_2… condition_n: They are used to specify the conditions to be strictly followed for selection.

Example: Students table:

ID NAME AGE
1 Joy 5
2 Smiley 13
3 Happy 11
4 Tom 15
5 Jerry 10
6 Bruno  6
7 David  8

Query:

SELECT *
FROM “STUDENTS”   
WHERE  ( “AGE” > 10  AND “ID” = 2 )
OR “AGE” = 15
ORDER BY “NAME”;

Output:

ID NAME AGE
2 Smiley 13
4 Tom 15
Please follow and like us:
Content Protection by DMCA.com