SQL UNION问题 [英] SQL UNION Question
本文介绍了SQL UNION问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以向我解释为什么使用SQL语句吗?
Can someone explain to me why the SQL statement:
SELECT 'TEST1'
UNION SELECT 'TEST2'
UNION SELECT 'TEST3'
返回:
TEST2
TEST3
TEST1
我试图弄清楚 UNION
关键字背后的逻辑。
是否有办法让我返回:
I am trying to figure out the logic behind the UNION
keyword in this aspect.
Is there a way I could get it to return:
TEST1
TEST2
TEST3
是否不使用 ORDER BY
子句?换句话说,我可以控制 UNION
语句的执行顺序吗?
without using the ORDER BY
clause? In other words, can I control the execution order of the UNION
statements?
如果有关系,我正在使用Postgre 9.0和PHP作为我的语言
If it matters, I am using Postgre 9.0 and PHP as my language
非常感谢,
Brett
Many thanks, Brett
推荐答案
UNION有效地将query2的结果附加到query1的结果(尽管不能保证这是其中的顺序实际返回的行)。
这篇关于SQL UNION问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文