DEV Community

Slava Rozhnev
Slava Rozhnev

Posted on

MySQL 8: short syntax for select all

Since MySQL 8 you can use pretty short query to select all data from table.
Just use TABLE a; instead SELECT * FROM a; and get same result

mysql> table a;
+===+===+
| m | n |
+===+===+
| 1 | 2 |
| 2 | 3 |
| 3 | 4 |
+---+---+

mysql> table b;
+===+===+
| m | n |
+===+===+
| 1 | 2 |
| 1 | 3 |
| 3 | 4 |
+---+---+

mysql> table c;
+===+===+
| m | n |
+===+===+
| 1 | 3 |
| 1 | 3 |
| 3 | 4 |
+---+---+
Enter fullscreen mode Exit fullscreen mode

The TABLE statement can be used with ORDER BY and LIMIT statements

mysql> table a order by n;
+===+===+
| m | n |
+===+===+
| 1 | 2 |
| 2 | 3 |
| 3 | 4 |
+---+---+

mysql> table b limit 2;
+===+===+
| m | n |
+===+===+
| 1 | 2 |
| 1 | 3 |
+---+---+

Enter fullscreen mode Exit fullscreen mode

This syntax also can be used with UNION statement

mysql> table a union all table b union all table c;
+===+===+
| m | n |
+===+===+
| 1 | 2 |
| 2 | 3 |
| 3 | 4 |
| 1 | 2 |
| 1 | 3 |
| 3 | 4 |
| 1 | 3 |
| 1 | 3 |
| 3 | 4 |
+---+---+
Enter fullscreen mode Exit fullscreen mode

SQLize.online - free online SQL environment

Top comments (1)

Collapse
 
gbhorwood profile image
grant horwood

i would actually use this!