Skip to content

Instantly share code, notes, and snippets.

@cinic
Last active October 21, 2016 00:07
Show Gist options
  • Select an option

  • Save cinic/b1ba0f13571bbe561b68c5f190315414 to your computer and use it in GitHub Desktop.

Select an option

Save cinic/b1ba0f13571bbe561b68c5f190315414 to your computer and use it in GitHub Desktop.
Nested select with union
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