PostgreSQL WHERE Clause

In PostgreSQL, WHERE clause specifies a certain condition in the query and records are filtered from the database according to that condition.In short, Where clause is used to filter the data from the rest of the table.
Where clause is used with SELECT, UPDATE, DELETE statement.The conditions are used to filter the rows returned in the SELECT statement.
If the given condition is satisfied, only then it returns the specific value from the table. You can filter rows that you do not want to include in the result-set using the WHERE clause.


WHERE Syntax :

The syntax of the WHERE statement is −

SELECT column1, column2, columnN
FROM table_name
WHERE [search_condition]



WHERE Example :

Consider the STUDENT table is having the following records

ID NAME AGE ADDRESS
1 Jugal 20 Mysore
2 Kartik 19 Delhi
3 Ashish 21 Udaipur
4 Prateek 19 Jaipur
5 Pranjal 20 Mumbai
6 Vivek 19 Mumbai

TEST CASE 1 :- The following code is an example, which would fetch the all record from STUDENT table where AGE is greater equal to 20.

lfcdb=# SELECT * FROM STUDENT WHERE AGE >= 20


The result for the respective query is as follows −

ID NAME AGE ADDRESS
1 Jugal 20 Mysore
5 Pranjal 20 Mumbai
3 Ashish 21 Udaipur



TEST CASE 2:- The following code is an example, which would fetch the all record from STUDENT table, where name start with 'Pr'.

lfcdb=# SELECT * FROM STUDENT WHERE NAME LIKE 'Pr%';


The result for the respective query is as follows −

ID NAME AGE ADDRESS
5 Pranjal 20 Mumbai
4 Prateek 19 Jaipur





Visit :


Discussion



* You must be logged in to add comment.