在SQL Server 2008中使用联接从不同的表中选择唯一的列名,而无需使用表别名 [英] to select the unique column names from different tables using join without use of table alias in sql server 2008

查看:83
本文介绍了在SQL Server 2008中使用联接从不同的表中选择唯一的列名,而无需使用表别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在SQL Server 2008中使用联接从不同的表中选择唯一的列名,而不使用表别名.

I want to select the unique column names from different tables using join without use of table alias in sql server 2008

Declare @SelectClause varchar(max);
set @SelectClause =''column1,column2,column3'';
Declare @qry varchar(max);

set @qry= ''Select '' + @SelectClause  + '' from table1 acc with(Nolock) join table2 ic with(Nolock) on acc.column1=ic.column1 ''
execute(@qry)


这里column1和column2都在table1和table2中
等待您的答复.
谢谢,提前.


here column1 and column2 both are in table1 as well as table2

waiting for your reply.
Thanks, In advance.

推荐答案

Use EXISTS like:
Code Snippet
select *
from t1
where exists(select * from t2 where t2.col1 = t1.col1 and t2.col2 = t1.col2 ...)


这篇关于在SQL Server 2008中使用联接从不同的表中选择唯一的列名,而无需使用表别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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