SQL queries are used to obtain data from databases. A query can be used with various clauses, such as conditional clauses (like WHERE) and sort clauses (like ORDER BY), to obtain query results.
Syntax
An SQL query is a SELECT statement used to query data from one or multiple tables or views. The SELECT statement can complete simple single-table queries and complex connection queries and embedded queries.
Syntax for the simplest SQL statement:
SELECT <select_list> [ FROM <table_list>]
Parameters in the syntax:
select_listspecifies the columns, or functions, constants, or variables from thetable_listthat follows.table_listspecifies the tables or views that contain the data to be retrieved.
Considerations
table_list can also specify a subquery statement that contains the WHERE clause to ensure that the returned result complies with certain conditions. Example:
SELECT * FROM table_a t1 WHERE t1.pk IN (SELECT t2.pk FROM table_b t2);
In MySQL mode, the FROM table_list clause is optional. Without this clause, select_list does not specify a specific column but a constant or variable. Example:
obclient> SELECT 'Medium', 6*6 ;
+-------+-----+
| Medium| 6*6 |
+-------+-----+
| Medium| 36 |
+-------+-----+
1 row in set
For more information about how to use query statements, see SELECT.