TeamForm Reports uses SQL which is a standard language for accessing and manipulating databases.
This page introduces query basics. For detailed SQL query syntax, see here |
The SELECT
statement is used to select data from a table.
The data returned is stored in a result table, called the result-set.
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:
SELECT * FROM table_name |
The WHERE
clause is used to filter records.
The WHERE
clause is used to extract only those records that fulfil a specified condition.
SELECT column1, column2, ... FROM table_name WHERE condition |
The following SQL statement selects the firstname
and surname
of all the people from the country =
‘Mexico', in the people
table:
SELECT firstname, surname FROM people WHERE country = 'Mexico' |
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.
SELECT column1, column2, ... FROM table_name WHERE condition ORDER BY column 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):
SELECT firstname, surname FROM people WHERE country = 'Mexico' ORDER BY surname |
You could also add the keyword ASC
but in this case, the default behaviour is 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):
SELECT firstname, surname FROM people WHERE country = 'Mexico' ORDER BY surname |
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):
SELECT firstname, surname FROM people WHERE country = 'Mexico' ORDER BY surname DESC, firstname ASC |
It is also possible to reference your columns numerically int he order they appear in the select statement e.g. |
This might cause more confusion if you have a lot of columns in your |
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/
|