Last active
October 21, 2016 00:07
-
-
Save cinic/b1ba0f13571bbe561b68c5f190315414 to your computer and use it in GitHub Desktop.
Nested select with union
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT id, x | |
| FROM ( | |
| SELECT id, x | |
| FROM test | |
| WHERE x='y' | |
| LIMIT 1 | |
| ) t1 | |
| UNION ALL | |
| SELECT id, x | |
| FROM ( | |
| SELECT id, x | |
| FROM test | |
| ORDER BY id DESC | |
| LIMIT 5 | |
| ) t2; | |
| # Или так | |
| (SELECT id, x | |
| FROM test | |
| WHERE x='y' | |
| LIMIT 1) | |
| UNION ALL | |
| SELECT id, x | |
| FROM ( | |
| SELECT id, x | |
| FROM test | |
| ORDER BY id DESC | |
| LIMIT 5 | |
| ) t2; | |
| # Или вот так | |
| (SELECT id, x | |
| FROM test | |
| WHERE x='y' | |
| LIMIT 1) | |
| UNION ALL | |
| ( | |
| SELECT id, x | |
| FROM test | |
| ORDER BY id DESC | |
| LIMIT 5 | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment