SQL中的INNER JOIN表 [英] INNER JOIN tables in SQL

查看:107
本文介绍了SQL中的INNER JOIN表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下SQL脚本。我想从另一个表中INNER JOIN一个表,但似乎它不能像我执行查询时那样,它返回一些错误,如下所示:

多个部件标识符  ProductDetail.RelationId无法绑定。





以下是我的SQLscript:



  SELECT  
cd.CustomerName
,cd.CustomerAddress
,pr.ProductName
FROM
CustomerDetail AS cd
INNER 加入 ProductRelation as pr
ON pr.RelationId = ProductDetail.RelationId







由于某些逻辑原因,我无法删除CustomerDetail表。但是有没有我可以一起加入ProductRelation和ProductDetail表?

解决方案

检查你使用过CustomerDetail和ProductRelation的FROM子句,那么ProductDetail别名来自哪里?试试这个



  SELECT  
cd.CustomerName
,cd.CustomerAddress
,pr.ProductName
FROM
CustomerDetail AS cd
INNER JOIN ProductRelation as pr
ON pr.RelationId = cd.RelationId


Hi, I have the following SQL scripts. I want to INNER JOIN a table from another table, but seems like it cant as when I execute the query, it returns me some error as below:

The multi-part identifier "ProductDetail.RelationId" could not be bound.



Below is my SQLscript:

SELECT
	 cd.CustomerName	
	,cd.CustomerAddress 
	,pr.ProductName
FROM
	CustomerDetail AS cd
	INNER JOIN ProductRelation as pr
		ON pr.RelationId = ProductDetail.RelationId




For some logic reason, I cannot remove the CustomerDetail table. But is there anyway I can join ProductRelation and ProductDetail table together?

解决方案

Check your FROM Clause you have used CustomerDetail and ProductRelation, so from where ProductDetail alias comes?

Try this

SELECT
	 cd.CustomerName	
	,cd.CustomerAddress 
	,pr.ProductName
FROM
	CustomerDetail AS cd
	INNER JOIN ProductRelation as pr
		ON pr.RelationId = cd.RelationId


这篇关于SQL中的INNER JOIN表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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