Last updated on March 14, 2023
The SELECT statement selects the data from a table in the database. It can select all the available column values from a table in the shape of a row. Also, it allows you to select specific columns, in case you don’t need all the values.
Syntax
SELECT columnOne, columnTwo FROM tableName;
Usage
To understand the select statement, look at the table below which has students’ data that need to be fetched through the select query.
StudentID | StudentName | StudentClass | StudentMarks |
1 | Emily | 5th | 450 |
2 | John | 6th | 430 |
3 | Elon | 8th | 510 |
To fetch all the rows from the above students table, you need to use select statement with asterisk (*).
SELECT * FROM students;
The above select query fetches all the columns from the students table. To get specific columns from the students table, you can specify the columns’ names.
SELECT StudentID, StudentName FROM students;
In this select query, we specified columns’ names with a select statement to fetch them. So it will be fetching only StudentID and StudentName columns’ data.