I currently have 12 fairly simple SQL queries which are used to pull data meeting different criteria to create a status page for displaying the priority order of received support emails.
我目前有12个相当简单的SQL查询,用于提取符合不同标准的数据,以创建状态页面,用于显示收到的支持电子邮件的优先顺序。
However, what I need to do is have a single DataTable that displays the following:
但是,我需要做的是有一个显示以下内容的DataTable:
Col1 | Col2 | Col3 | Col4
Data from SQL Query 1
.... | .... | .... | ....
.... | .... | .... | ....
Data from SQL Query 2
.... | .... | .... | ....
.... | .... | .... | ....
Data from SQL Query 3
.... | .... | .... | ....
.... | .... | .... | ....
etc
So each query is run, then its data added to the datatable after the previous query (no sorting takes place, and all rows are added in the order each SQL query returns them).
因此,每个查询都会运行,然后在上一个查询之后将其数据添加到数据表中(不进行排序,并按照每个SQL查询返回的顺序添加所有行)。
I have tried using an SQL UNION
statement to combine all SQL queries together, however the results returned become ordered by ID across all rows which isn't what I want.
我已经尝试使用SQL UNION语句将所有SQL查询组合在一起,但是返回的结果将按所有行的ID排序,这不是我想要的。
1 个解决方案
#1
3
Data doesn't have any ORDER other than that which you specifically specify. If you want to order the data in a specific manner, add it to your query.
除了您明确指定的数据之外,数据没有任何ORDER。如果要以特定方式订购数据,请将其添加到查询中。
If you want the rows from query 1 first, then add an extra column indicating that to your query
如果您想首先查询查询1中的行,则添加一个额外的列,指示您的查询
select 1 as priority, field1, field2 from ...
union
select 2 as priority, field1, field2 from ...
order by priority
#1
3
Data doesn't have any ORDER other than that which you specifically specify. If you want to order the data in a specific manner, add it to your query.
除了您明确指定的数据之外,数据没有任何ORDER。如果要以特定方式订购数据,请将其添加到查询中。
If you want the rows from query 1 first, then add an extra column indicating that to your query
如果您想首先查询查询1中的行,则添加一个额外的列,指示您的查询
select 1 as priority, field1, field2 from ...
union
select 2 as priority, field1, field2 from ...
order by priority