我想显示两个不同表的值,以及该表中两个不同的列,按升序排序。
我该怎么做?
我用它来显示两个表的值,但是按升序排序:
select
distinct varWinePrice
from
tbl_wines
union
select
distinct varPrice
from
tbl_price
答案 0 :(得分:3)
如果列名不同,则应使用第一个子选择的列进行排序:
select distinct varWinePrice
from `tbl_wines`
union
select distinct varPrice
from tbl_price
order by varWinePrice
答案 1 :(得分:2)
select distinct varWinePrice as x from tbl_wines union
select distinct varPrice as x from tbl_price
order by x asc;
答案 2 :(得分:1)
您可以将UNION选择嵌套到外部选择
中select
pr.price
from (
select
distinct varWinePrice
from
tbl_wines
union
select
distinct varPrice
from
tbl_price
) pr
order by
pr.price
答案 3 :(得分:0)
您可以使用临时表按语法使用顺序:
1)创建临时表
2)在临时表中填写记录
3)通过应用order by clause
答案 4 :(得分:0)
SELECT Price
FROM ( SELECT DISTINCT varWinePrice AS Price FROM tbl_wines
UNION
SELECT distinct varPrice AS Price FROM tbl_price
)
ORDER BY Price