PostgreSQL SELECT Query
To extract data from a database, you need to use the PostgreSQL SELECT statement.The PostgreSQL Select statement is used to select or fetch data from the database table.The data return from the database table as the result table is also known as the result-set.
SELECT Syntax :
The SELECT statement is the most complex statement and can be combined with other clauses to form a powerful query.The syntax of the SELECT statement is −
SELECT column1, column2, columnN FROM table-name;
column1 , column2, column3: names of the fields of the table
table-name: table where we want to fetch data.
If we want to select all the columns from the respective table then we use the following syntax:
SELECT * FROM table-name;
SELECT Example :
Consider the STUDENT table is having the following records
ID | NAME | AGE | ADDRESS |
---|---|---|---|
1 | Rahul | 20 | Mysore |
2 | Kartik | 19 | Delhi |
3 | Nidhi | 21 | Udaipur |
4 | Prateek | 19 | Jaipur |
5 | Jugal | 20 | Mumbai |
6 | Abhi | 19 | Mumbai |
The following is an example, which would fetch ID and NAME record for a STUDENT.
lfcdb=# SELECT ID, NAME FROM STUDENT ;
All the above statements would create the following records in STUDENT table
ID | NAME |
---|---|
1 | Rahul |
3 | Nidhi |
4 | Prateek |
5 | Jugal |
6 | Abhi |
Visit :
Discussion