...
The SQL SELECT Statement
The SELECT
statement is used to select data from a table.
...
Code Block | ||
---|---|---|
| ||
SELECT column1, column2, ... FROM table_name |
Here, column1
, column2
, ... are the field names of the table you want to select data from. If you want to select all the fields available in the table, use the following syntax:
Code Block | ||
---|---|---|
| ||
SELECT * FROM table_name |
The SQL WHERE Clause
The WHERE
clause is used to filter records.
The WHERE
clause is used to extract only those records that fulfil a specified condition.
...
The following SQL statement selects the “firstname“ firstname
and “surname“ surname
of all the people from the country
"Mexico"=
‘Mexico', in the "people
" table:
Code Block | ||
---|---|---|
| ||
SELECT firstname, surname FROM people WHERE country = 'Mexico' |
Info |
---|
For conditions, you must use single 'quotations’ rather than double |
The SQL ORDER BY Clause
The ORDER BY
clause is used to sort your columns of data by a particular ordering e.g. ASC
ascending or DESC
descending and even across multiple columns for more advanced sorting.
...
The following SQL statement selects the firstname
and surname
of all the people from the country
‘Mexico’=
‘Mexico', in the people
table and then sorts by surname
in DESC
(descending order):
...
The following SQL statement selects the firstname
and surname
of all the people from the country
‘Mexico’=
‘Mexico', in the people
table and then sorts by surname
in ASC
(ascending order - the default):
...
The following SQL statement selects the firstname
and surname
of all the people from the country
‘Mexico’=
‘Mexico', in the people
table and then sorts by surname
in DESC
order and then firstname
in ASC
(ascending order - the default):
...