使用ORDER BY显示来自两个不同表的两个不同列 [英] Display two different columns from two different tables with ORDER BY

查看:102
本文介绍了使用ORDER BY显示来自两个不同表的两个不同列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示两个不同表的值,以及该表中两个不同列的值,并按升序排序.

I want to display the values of two different tables, and two different columns from that table, sorted in ascending order.

我该怎么做?

我用它来显示两个表的值,但是卡在升序的排序中:

I use this to display values of two tables, but stuck in sorting by ascending order:

select 
  distinct varWinePrice 
from 
  tbl_wines 
union 
select 
  distinct varPrice 
from 
  tbl_price

推荐答案

如果列名不同,则应使用第一个子选择的列进行排序:

If column names are different then sorting should be done using the column of the first subselect:

select distinct varWinePrice 
from `tbl_wines` 
union 
select distinct varPrice 
from tbl_price
order by varWinePrice

这篇关于使用ORDER BY显示来自两个不同表的两个不同列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆