Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Join two tables on multiple columns?

Status
Not open for further replies.

rrhandle

Programmer
Dec 26, 2001
193
US
How do I join two tables A and B on A.column1 = B.column1 and A.column2 = B.column2?

 
select * from tableA A
Join TableB B on A.column1 = B.column1 and A.column2 = B.column2

“I sense many useless updates in you... Useless updates lead to fragmentation... Fragmentation leads to downtime...Downtime leads to suffering..Fragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" --
 
SELECT A.*, B.*
FROM table1 A INNER JOIN
table2 B ON
A.col1=B.col1 AND
A.col2=B.col2

and so on...

-DNG
 
Thanks to both of you. That is what I tried, but ended up with way more records than I should have had. Now that I know my syntax was right, I know there are columns that don't match. Will have to find those columns. Thanks again.

 
Don't worry, SQLDenis. I, ispeaker, am really rrhandle who for some unknown reason have been unable to login for weeks, and no one will answer my e-mails, so I created a new account, and replied to this post to see what would happen.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top