IN condition in PostgreSQL

PostgreSQL IN To filter the results, the PostgreSQL IN condition is used with SELECT, INSERT, UPDATE and DELETE statements to replace the use of multiple OR conditions.

Syntax:

WHERE expressions IN (value1, value2, .... value_n);  

Parameters: expressions: It is used to specify a column or a field. value_1, value_2… value_n: They are used to specify the values to be tested against the expressions.

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 “NAME” IN (‘Joy’, 'Happy', 'Smiley')
ORDER BY “NAME”;

Output:

ID NAME AGE
3 Happy 11
1 Joy 5
2 Smiley 13
Please follow and like us:
Content Protection by DMCA.com