是否可以使用SQL从不同的表中提取数据,然后根据所有表中的一列对数据进行排序。例如,我有3张桌子。基础,选择,子。他们都有3个职位栏,
Select base_layers.position, selects.position, subbases.position
from base_layers,selects,subbases
Order By (alls)position;
这正是我真正想要做的......但感觉这是不可能的。
答案 0 :(得分:3)
使用联盟:
(我假设您不想交叉加入所有3个表格)
select Position
from
(
select base_layers.position AS Position
from base_layers
union
select selects.position
from selects
union
select subbases.position
from subbases
) x
order by Position ASC;
答案 1 :(得分:0)
您的语法不正确。试试这个版本。
SELECT * FROM
(
SELECT base_layers.position
FROM base_layers
UNION ALL
SELECT selects.position
FROM selects
UNION ALL
SELECT subbases.position
FROM subbases
) tbl ORDER BY tbl.position;