The SELECT statement in SQL is used to retrieve data from one or more tables.
SELECT statement allows you to specify which columns you want to retrieve from Tables.
SQL provides operators to perform operations while retrieving data from a table such as filtering, sorting, grouping, and limiting operations.
Here is the basic syntax of the SELECT statement:
SELECT column1, column2, ... FROM table_name WHERE condition;
column1, column2, ...: The columns you want to retrieve from the table. You can use an asterisk (*) to select all columns.
table_name: The name of the table from which you want to retrieve data.
WHERE condition: An optional clause that allows you to filter the results based on a specified condition
`*` syntax indicates that we want to retrieve all columns from the table.
SELECT * FROM products;
Defining names in the `SELECT` statement indicates that we want to retrieve these Columns from tables. for ex:- in the below query we have specified `product_name`, `product_price`, `category`.
SELECT product_name, product_price, category FROM products;
Defining the `WHERE` clause in the `SELECT` statement indicates that we want to filter out data based on the Column from the table. for ex:- in the below query we have specified `category = GAMES`. so it will retrieve all records from the table where a `category` is equal to `GAMES`.
SELECT * FROM products WHERE category = 'GAMES';
Defining the `DISTINCT` Operator in the `SELECT` statement indicates that we want to retrieve unique records based on specific Columns from the Table.
SELECT DISTINCT category FROM products;
The `LIMIT` Operator applies a limit on Query to return a Specific Number of Records from the table.
SELECT * FROM products LIMIT 20;
The above query will return 20 records from the table.