SQL从多个表中选择不同的值 [英] SQL Select distinct values from multiple tables
本文介绍了SQL从多个表中选择不同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以这是我的设置,我有2个旧表和新表,具有以下(简化的)模式
So here's my setup I have 2 tables Old and New with the following (simplified) schemas
Old
[ManName]
[ManNumber]
New
[Manager_Name]
[Manager_Number]
我正在寻找一种SQL查询,该查询返回以下内容,但在1个查询中包含4列,而不是2个查询,每个查询具有2列
I'm looking to craft a SQL query that returns the following but in 4 columns in 1 query as opposed to 2 queries with 2 columns each
select distinct manname, mannumber from OLD
select distinct Manager_Name, Manager_Number from NEW
所以我理想的结果集应该有4列:
So my ideal Result Set would have 4 columns:
ManName ManNumber Manager_Name Manager Number
谢谢!
推荐答案
您是否尝试过JOIN语句:
have you tried a JOIN statement:
select distinct *
from old a join new b on a.ManName = b. Manager_Name and a. ManNumber = b. Manager_Number
这篇关于SQL从多个表中选择不同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文