December 23, 2010 at 7:54 am
Hey guys,
So here's sample syntax for joining two tables:
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
FROM Persons
INNER JOIN Orders
ON Persons.P_Id=Orders.P_Id
In this example, this is possible since column name "Id" are the same in both tables.
However, my question is it possible to somehow still join on this common column, if it's named differently in each table? If not, is there an equivalent statement that would still do this? To elaborate, I want to return all values in one column, that have corresponding equal / same values in another column from a different table (again this column is named differently in this other table).
Thank You
December 23, 2010 at 8:01 am
The syntax is the same, the column names don't have to be the same at all. In your example, you specify both column names, you do it exactly the same way if they're named differently, there's nothing in your example that requires the join columns to have the same name.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
December 23, 2010 at 8:17 am
Wow, I just tried it, and it worked perfectly! Thanks!
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply