我有查询
SELECT id, name
FROM users
WHERE id !=2
UNION
SELECT id, name
FROM users2
WHERE id != 3;
我希望那种类型,1联盟命令+ 2联合它可能吗?
答案 0 :(得分:2)
在
上添加要订购的列SELECT id, name, 1 as unionOrder FROM users WHERE id !=2
UNION
SELECT id, name, 2 as unionOrder FROM users2 WHERE id != 3
ORDER BY unionOrder
答案 1 :(得分:1)
您也可以这样做
(SELECT id, name
FROM users
WHERE id !=2
ORDER BY id)
UNION ALL
(SELECT id, name
FROM users2
WHERE id != 3
ORDER BY id);