); 

When we run on test2  the same two REPLACE  statements as we did on the original test  table, we obtain a different result: 

mysql> REPLACE INTO test2 VALUES (1, ’Old’, ’2014-08-20 18:47:00’); Query OK, 1 row affected (0.05 sec) mysql> REPLACE INTO test2 VALUES (1, ’New’, ’2014-08-20 18:47:42’); Query OK, 1 row affected (0.06 sec) mysql> SELECT * FROM test2; +----+------+---------------------+ | id | data | ts | +----+------+---------------------+ | 1 | Old | 2014-08-20 18:47:00 | | 1 | New | 2014-08-20 18:47:42 | +----+------+---------------------+ 2 rows in set (0.00 sec) 

This is due to the fact that, when run on test2 , both the id  and ts  column values must match those of an existing row for the row to be replaced; otherwise, a row is inserted. 

## 13.2.10 SELECT Statement 

SELECT [ALL | DISTINCT | DISTINCTROW ] [HIGH_PRIORITY] [STRAIGHT_JOIN] [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT] [SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS] select_expr  [, select_expr ] ... [ into_option ] [FROM table_references [PARTITION partition_list ]] [WHERE where_condition ] [GROUP BY { col_name  | expr  | position }, ... [WITH ROLLUP]] [HAVING where_condition ] [WINDOW window_name  AS ( window_spec ) [, window_name  AS ( window_spec )] ...] [ORDER BY { col_name  | expr  | position } [ASC | DESC], ... [WITH ROLLUP]] [LIMIT {[ offset ,] row_count  | row_count  OFFSET offset }] [ into_option ] [FOR {UPDATE | SHARE} [OF tbl_name  [, tbl_name ] ...] [NOWAIT | SKIP LOCKED] | LOCK IN SHARE MODE] [ into_option ] into_option : { INTO OUTFILE ’ file_name ’ [CHARACTER SET charset_name ] export_options | INTO DUMPFILE ’ file_name ’ | INTO var_name  [, var_name ] ... } 

SELECT  is used to retrieve rows selected from one or more tables, and can include UNION  statements and subqueries. See Section 13.2.10.3, “UNION Clause” , and Section 13.2.11, “Subqueries” . A SELECT statement can start with a WITH  clause to define common table expressions accessible within the SELECT . See Section 13.2.15, “WITH (Common Table Expressions)” . 

The most commonly used clauses of SELECT  statements are these: 

