SELECT * FROM table 1 UNION SELECT * FROM table 2
现在我从两个表中随机获取数据
但我需要先显示table2数据后显示table1数据
答案 0 :(得分:1)
在实践中,这将做你想要的(假设表有相同的列):
SELECT * FROM table1
UNION ALL
SELECT * FROM table2;
使用明确的order by
:
SELECT . . .
FROM (SELECT t1.*, 1 as which FROM table1 t1
UNION ALL
SELECT t2.*, 2 as which FROM table2 t2
) t
ORDER BY which;
SQL表代表无序集。没有ANSI要求UNION ALL
在第二个子查询之前从第一个子查询返回值。在实践中适用于MySQL。
答案 1 :(得分:1)
一种方法是在两个查询中添加一个列,指示源来自哪里。
{% include 'forms/form.html.twig' with { form: forms('sign-up-form') } %}
{% include 'forms/form.html.twig' with { form: forms('footer-form') } %}