首页 > 解决方案 > 将table1中的column1与table2中的column1匹配,并返回table2中与table1的column1匹配的*记录

问题描述

我试过这个:

select *
from table2
where exists (
    select *
    from table1
    where table2.column1 = table1.column1
)

输出:它返回 table2 中列的所有表头,但不返回任何记录。

观察:当我尝试匹配值间列时,它正在返回记录。但是在匹配字符值列时它不起作用

注意:table1 和 table2 中的 column1 都具有字符值。

select [Data Name]
from [DynamicDataTable]
where exists (
    select *
    from University_Temp
    where DynamicDataTable.autocode = University_Temp.autocode
)

上述查询的输出

[Data Name]
Title  
First Name  
Geebee Centre  
Country of Permanent Residence  
SSC Institute/College  

上面的查询返回匹配自动代码的记录,这些记录是数据类型的整数。

标签: sqlsql-serverdatabase

解决方案


因此,您想查看table2whereColumn1Column1from匹配的所有行table1
如果我理解正确,这只是一个简单的加入

select t2.*
from   table2 t2
  inner join table1 t1 on t2.Column1 = t1.Column1

如果这不是您想要的,请编辑您的问题并更详细地解释您需要什么


推荐阅读