SELECT

Description

Retrieves data from a table.

Syntax

  1. SELECT
  2. [ALL | DISTINCT ]
  3. select_expr [, select_expr] [[AS] alias] ...
  4. [INTO variable [, ...]]
  5. [FROM table_references
  6. [WHERE where_condition]
  7. [GROUP BY {col_name | expr | position}
  8. [ASC | DESC]]
  9. [HAVING where_condition]
  10. [ORDER BY {col_name | expr | position}
  11. [ASC | DESC]]
  12. [LIMIT {[offset,] row_count | row_count OFFSET offset}]

Examples

  1. > SELECT number FROM numbers(3);
  2. +--------+
  3. | number |
  4. +--------+
  5. | 0 |
  6. | 1 |
  7. | 2 |
  8. +--------+
  9. > SELECT * FROM t1 WHERE spID>2 AND userID <2 || userID >=2 OR userID < 2 LIMIT 3;
  10. > SELECT userID,MAX(score) max_score FROM t1 WHERE userID <2 || userID > 3 GROUP BY userID ORDER BY max_score;
  11. > create table t1 (spID int,userID int,score smallint);
  12. > insert into t1 values (1,1,1);
  13. > insert into t1 values (2,2,2);
  14. > insert into t1 values (2,1,4);
  15. > insert into t1 values (3,3,3);
  16. > insert into t1 values (1,1,5);
  17. > insert into t1 values (4,6,10);
  18. > insert into t1 values (5,11,99);
  19. > select userID,count(score) from t1 group by userID having count(score)>1 order by userID;
  20. +--------+--------------+
  21. | userid | count(score) |
  22. +--------+--------------+
  23. | 1 | 3 |
  24. +--------+--------------+
  25. > select userID,count(score) from t1 where userID>2 group by userID having count(score)>1 order by userID;
  26. Empty set (0.01 sec)s

Constraints

  1. Table alias is not supported in GROUP BY.
  2. SELECT…FOR UPDATE clause is not supported now.
  3. INTO OUTFILE is limitedly support.