What is SQL SELECT statement?
The SQL SELECT statement is used to fetch data from a database table which returns the data in the form of a result table. These result tables are called result sets.
Basic syntax
SELECT column1, column2, column3 FROM table_name;
The query contains two keywords – SELECT and FROM. The SELECT keyword means that we want to select/display/generate a result set from the listed columns – column1, column2, column3. The FROM keyword specifies the source of the selected columns (in this case this is the name of the table). If we want to select all of the columns we can use the symbol “*” as shown below:
SELECT * FROM table_name;
Example
Lets have a demo table called Persons:
Id | Name | Age |
1 | John | 20 |
2 | Anna | 35 |
3 | Peter | 25 |
4 | Ivan | 22 |
5 | Don | 32 |
If we execute any of following queries:
SELECT * FROM Persons;
SELECT Id, Name, Age FROM Persons;
We will get the same result – the whole data from the table.
If we want to select only the names of the persons we can execute:
SELECT Name FROM Persons;
Leave A Comment