This works
SELECT *
FROM foo
UNION
SELECT *
FROM bar
This gives me a "syntax error near UNION".
SELECT *
FROM foo
ORDER BY random() LIMIT 1000
UNION
SELECT *
FROM bar
ORDER BY random() LIMIT 1000;
Why is that? How to UNION tables with ORDER BY and LIMIT?
>Solution :
You need to place each half of the union into a separate subquery:
(SELECT * FROM foo ORDER BY RANDOM() LIMIT 1000)
UNION ALL
(SELECT * FROM bar ORDER BY RANDOM() LIMIT 1000);