sql query to show joined tables by id
I have Table A:
ID | Fname
1 | aaa
2 | bbb
3 | ccc
4 | ddd
and Table B:
ID | Age
1 | 50
2 | 60
8 | 70
4 | 80
I need to run query that show me this:
ID | Fname | Age
1 | 开发者_Python百科aaa | 50
2 | bbb | 60
4 | ddd | 80
need it on sql server 2008
Seems like a really really simple INNER JOIN
- try this:
SELECT A.ID, A.FName, B.Age
FROM dbo.TableA A
INNER JOIN dbo.TableB B ON A.ID = B.ID
See Jeff Atwood's visual explanation of what the different types of JOINs in SQL are and what they do.
SELECT a.ID, a.Fname, b.Age
FROM TableA AS a
INNER JOIN TableB AS b ON a.ID = b.ID
精彩评论