SQL SELECT Statement

By Hemanta Sundaray on 2022-12-18

SELECT statements are used to fetch data from a database. In the statement below, SELECT returns all data in the name column of the students table.

SELECT name FROM students;
  • SELECT is a clause that indicates that the statement is a query. You will use SELECT every time you query data from a database.
  • name specifies the column to query data from.
  • FROM students specifies the name of the table to query data from. In this statement, data is queried from the students table.

Select Multiple Columns

Suppose you are only interested in two columns: name & age. You can select individual columns by their names (separated by comma):

SELECT name, age
FROM students;

To make it easier to read, we have moved FROM to another line.

Note that line breaks don't mean anything specific in SQL. We could write the entire query in one line, and it would run just fine.

Select All Columns

You can also query data from all columns in a table with SELECT.

SELECT * FROM students;

* is a special wildcard character that we have been using. It allows you to select every column in a table without having to name each one individually. Here, the result set contains every column in the celebs table.

SELECT statements always return a new table called the result set.

Join the Newsletter