DEV Community

Ezhil Abinaya K
Ezhil Abinaya K

Posted on

Select Query

Select Data
To retrieve data from a data base, we use the SELECT statement.
Specify Columns
By specifying the column names, we can choose which columns to select:

SELECT brand, year FROM cars;
Enter fullscreen mode Exit fullscreen mode

Return ALL Columns
Specify a * instead of the column names to select all columns:

SELECT * FROM cars;
Enter fullscreen mode Exit fullscreen mode

Display Table
To check the result we can display the table with this SQL statement:

SELECT * FROM cars;
Enter fullscreen mode Exit fullscreen mode

PostgreSQL Operators
Greater Than
The > operator is used when you want to return all records where a columns is greater than a specified value.
Return all records where the year is greater than 1975:

SELECT * FROM cars
WHERE year > 1975;
Enter fullscreen mode Exit fullscreen mode

Less Than or Equal To
The <= operator is used when you want to return all records where a column is less than, or equal to, a specified value.
Return all records where the year is less than or equal to 1975:

SELECT * FROM cars
WHERE year <= 1975;
Enter fullscreen mode Exit fullscreen mode

Reference
https://www.w3schools.com/postgresql/postgresql_operators.php

Top comments (0)