SQL Server: Join two tables returning only one row from the second table - TechRepublic
Question
October 18, 2012 at 12:11 AM
axesharpeye

SQL Server: Join two tables returning only one row from the second table

by axesharpeye . Updated 13 years, 8 months ago

TABLE1

ID (PK) Name
1001 Sam

TABLE2

IDadd (FK) Country
1001 USA
1001 UK

My query:

SELECT A.Name, B.Country
FROM TABLE1 A
INNER JOIN (SELECT TOP 1 * FROM TABLE2 WHERE IDadd = A.ID) AS B
ON B.IDadd = A.ID

Basically, the query intends to get one of the records from TABLE2 and join it to TABLE1. However, I can’t get it to work.

Any help is highly appreciated!

This discussion is locked

All Comments