...
The data returned is stored in a result table, called the result-set.
SELECT Syntax
Code Block |
---|
|
SELECT column1, column2, ...
FROM table_name |
...
The WHERE
clause is used to extract only those records that fulfil a specified condition.
WHERE Syntax
Code Block |
---|
|
SELECT column1, column2, ...
FROM table_name
WHERE condition |
Example
The following SQL statement selects the firstname
and surname
of all the people from the country =
‘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.
ORDER BY Syntax
Code Block |
---|
|
SELECT column1, column2, ...
FROM table_name
WHERE condition
ORDER BY column order |
Example Descending order
The following SQL statement selects the firstname
and surname
of all the people from the country =
‘Mexico', in the people
table and then sorts by surname
in DESC
(descending order):
...
You could also add the keyword ASC
but in this case, the default behaviour is ascending order.
Example Ascending order
The following SQL statement selects the firstname
and surname
of all the people from the country =
‘Mexico', in the people
table and then sorts by surname
in ASC
(ascending order - the default):
Code Block |
---|
|
SELECT firstname, surname
FROM people
WHERE country = 'Mexico'
ORDER BY surname |
Example ORDER BY Multiple Columns
The following SQL statement selects the firstname
and surname
of all the people from the country =
‘Mexico', in the people
table and then sorts by surname
in DESC
order and then firstname
in ASC
(ascending order - the default):
...
If you are interested in digging further into SQL there are a wealth of resources (articles, books, videos online) and your organisation may even have a learning platform with paid resources for you to learn from. In the mean time a useful basic cheatsheet can be found here:https://learnsql.com/blog/sql-basics-cheat-sheet/
Related
...
Pages
Filter by label (Content by label) |
---|
showLabels | false |
---|
max | 5 |
---|
spaces | com.atlassian.confluence.content.render.xhtml.model.resource.identifiers.SpaceResourceIdentifier@9e4 |
---|
maxCheckbox | false |
---|
showSpace | false |
---|
sort | modified |
---|
type | page |
---|
reverse | true |
---|
labels | queries reporting fields tables sql |
---|
cql | label in ( "reporting" , "queries" , "tables" , "fields" , "sql" , "redash" , "dashboard" , "dashboards" ) and type = "page" and space = "OS" |
---|
|