SQL SELECT Statement
In SQL, the SELECT statement is used to query or retrieve data from a table in the database. The returns data is stored in a table, and the result table is known as result-set.
Syntax
Here, the expression is the field name of the table that you want to select data from.
Use the following syntax to select all the fields available in the table:
Example:
EMPLOYEE
EMP_ID | EMP_NAME | CITY | PHONE_NO | SALARY |
---|---|---|---|---|
1 | Kristen | Chicago | 9737287378 | 150000 |
2 | Russell | Austin | 9262738271 | 200000 |
3 | Angelina | Denver | 9232673822 | 600000 |
4 | Robert | Washington | 9367238263 | 350000 |
5 | Christian | Los angels | 7253847382 | 260000 |
To fetch the EMP_ID of all the employees, use the following query:
Output
EMP_ID |
---|
1 |
2 |
3 |
4 |
5 |
To fetch the EMP_NAME and SALARY, use the following query:
EMP_NAME | SALARY |
---|---|
Kristen | 150000 |
Russell | 200000 |
Angelina | 600000 |
Robert | 350000 |
Christian | 260000 |
To fetch all the fields from the EMPLOYEE table, use the following query:
Output
EMP_ID | EMP_NAME | CITY | PHONE_NO | SALARY |
---|---|---|---|---|
1 | Kristen | Chicago | 9737287378 | 150000 |
2 | Russell | Austin | 9262738271 | 200000 |
3 | Angelina | Denver | 9232673822 | 600000 |
4 | Robert | Washington | 9367238263 | 350000 |
5 | Christian | Los angels | 7253847382 | 260000 |
0 Comments