SELECT

The SELECT statement is used to retrieve data from a table. See the SELECT page for more details such as syntax, remarks, and examples.

The SELECT clause specifies the columns to be retrieved from the table(s). All columns can be specified. Distinct (not repeated) values for a column can also be specified. The SELECT page gives details of the syntax for these options.

The following clauses make up the basic parts of a SELECT statement. The clauses are optional except for the FROM clause in most cases.

The FROM Clause

The FROM clause specifies which table(s) data will be queried from. If multiple tables are queried, the subsequent table(s) that follow the first table will use a JOIN clause. See JOIN and Subqueries for details about join syntax.

The WHERE Clause

The WHERE clause specifies the conditions that must be met for a row to be included in the result set.

The GROUP BY and HAVING Clauses

The GROUP BY clause groups rows together that have the same values for columns listed in the SELECT clause. The GROUP BY clause must be used for columns not aggregated. See the Aggregate Functions section for more information on how to use the GROUP BY clause in queries that contain aggregate functions.

The HAVING clause is used to filter the results of queries that use a GROUP BY clause. The HAVING clause can refer to grouped and ungrouped columns.

The ORDER BY Clause

The ORDER BY clause sorts the result set of a query based on one or more columns. Either ascending (ASC) or descending (DESC) can be specified. By default, if you don't specify ASC or DESC, the sort will be in ascending order.

The LIMIT Clause

The LIMIT clause is used to restrict the number of rows returned in the result set to the number specified.

SQL Functions List - this is a list of all the SQL functions SingleStore current used. SQL Functions can be used in SELECT statements.

Last modified: June 22, 2023

Was this article helpful?