DEV Community

Slava Rozhnev
Slava Rozhnev

Posted on

5 1

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

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

Top comments (1)

Collapse
 
gbhorwood profile image
grant horwood

i would actually use this!

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay