The SELECT clause works with the WHERE clause to define what information you want your report to include.

It often contains column references which specify the data you want to retrieve from the table you choose in the FROM clause.

See the Appendix for a full list of columns.

For example, suppose you want to produce a table like this of all the tickets that meet a certain condition, e.g. awaiting agent:

../_images/select-table-example.png

Your SELECT clause would be a comma-separated list of column references:

SELECT tickets.id, tickets.subject, tickets.person, tickets.department, tickets.date_created, tickets.agent

The SELECT clause can also use DPQL List of functions [old]

For example, suppose you didn’t want a detailed table of all matching tickets, just the total number. You would use the DPQL_COUNT() function to count the total number of matching tickets.

SELECT DPQL_COUNT()

In table output, the header text for a column is automatically derived from the SELECT used to produce the column. This may not always result in a good column name; for example, if you just used SELECT COUNT(), you’ll produce a table like this:

../_images/select-naked-count.png

You can use an alias to specify a better name for a column.

DPQL_COUNT() AS 'Total Tickets'

would make the result display like this:

../_images/select-count-alias.png

If you want to retrieve all the columns from a table, you can use a wildcard such as SELECT people.

Published: 22/05/2018

Last updated: 22/05/2018