Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
The multi-part identifier "ProductDetail.RelationId" could not be bound.


Below is my SQLscript:

SQL
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?
Posted

1 solution

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

Try this

SQL
SELECT
	 cd.CustomerName	
	,cd.CustomerAddress 
	,pr.ProductName
FROM
	CustomerDetail AS cd
	INNER JOIN ProductRelation as pr
		ON pr.RelationId = cd.RelationId
 
Share this answer
 
Comments
Jamie888 4-Feb-16 2:50am    
Thank you for your suggestion sir. But unfortunately, in the CustomerDetail table do not have RelationId.
_Asif_ 4-Feb-16 4:23am    
so how can we turn this unfortunate event to fortune? :)
Jamie888 4-Feb-16 20:26pm    
Yes sir, fortune sure has come. I have use another table to join with CustomerDetail table before ProductRelation table. Then only I will use the value in the other table to continue to join back the ProductRelation table and subsequently ProductDetail table. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900