The PostgreSQL AND as well as administrators are utilized to consolidate numerous conditions to limit chosen information in a PostgreSQL proclamation. These two administrators are called conjunctive administrators.
These administrators give a way to make numerous examinations with various administrators in a similar PostgreSQL explanation.
The AND Operator
The AND administrator permits the presence of various conditions in a PostgreSQL articulation's WHERE proviso. While utilizing AND administrator, complete condition will be accepted genuine when all the conditions are valid. For instance [condition1] AND [condition2] will be genuine just when both condition1 and condition2 are valid.
Syntax
The fundamental punctuation of AND administrator with WHERE provision is as per the following −
SELECT column1, column2, columnN
FROM table_name
WHERE [condition1] AND [condition2]...AND [conditionN];
You can consolidate N number of conditions utilizing AND administrator. For a move to be made by the PostgreSQL proclamation, regardless of whether it be an exchange or inquiry, all conditions isolated by the AND should be TRUE.
Example
Consider the table COMPANY having records as follows −
testdb# select * from COMPANY;
id | name | age | address | salary
----+-------+-----+-----------+--------
1 | Paul | 32 | California| 20000
2 | Allen | 25 | Texas | 15000
3 | Teddy | 23 | Norway | 20000
4 | Mark | 25 | Rich-Mond | 65000
5 | David | 27 | Texas | 85000
6 | Kim | 22 | South-Hall| 45000
7 | James | 24 | Houston | 10000
(7 rows)
The accompanying SELECT assertion records down all the records where AGE is more noteworthy than or equivalent to 25 AND pay is more prominent than or equivalent to 65000.00 −
testdb=# SELECT * FROM COMPANY WHERE AGE >= 25 AND SALARY >= 65000;
The above given PostgreSQL explanation will deliver the accompanying outcome −
id | name | age | address | salary
----+-------+-----+------------+--------
4 | Mark | 25 | Rich-Mond | 65000
5 | David | 27 | Texas | 85000
(2 rows)
The OR Operator
The OR administrator is likewise used to join various conditions in a PostgreSQL proclamation's WHERE provision. While utilizing OR administrator, complete condition will be accepted genuine when at any rate any of the conditions is valid. For instance [condition1] OR [condition2] will be valid if either condition1 or condition2 is valid.
Syntax
The fundamental grammar of OR administrator with WHERE provision is as per the following −
SELECT column1, column2, columnN
FROM table_name
WHERE [condition1] OR [condition2]...OR [conditionN]
You can join N number of conditions utilizing OR administrator. For a move to be made by the PostgreSQL explanation, regardless of whether it be an exchange or question, just any of the conditions isolated by the OR should be TRUE.
Example
Consider the COMPANY table, having the accompanying records −
# select * from COMPANY;
id | name | age | address | salary
----+-------+-----+-----------+--------
1 | Paul | 32 | California| 20000
2 | Allen | 25 | Texas | 15000
3 | Teddy | 23 | Norway | 20000
4 | Mark | 25 | Rich-Mond | 65000
5 | David | 27 | Texas | 85000
6 | Kim | 22 | South-Hall| 45000
7 | James | 24 | Houston | 10000
(7 rows)
The accompanying SELECT assertion records down all the records where AGE is more noteworthy than or equivalent to 25 OR pay is more prominent than or equivalent to 65000.00 −
testdb=# SELECT * FROM COMPANY WHERE AGE >= 25 OR SALARY >= 65000;
The above given PostgreSQL articulation will deliver the accompanying outcome −
id | name | age | address | salary
----+-------+-----+------------+--------
1 | Paul | 32 | California | 20000
2 | Allen | 25 | Texas | 15000
4 | Mark | 25 | Rich-Mond | 65000
5 | David | 27 | Texas | 85000
(4 rows)