Reputation: 5
I have two tables. They follow the same ID records. table1:
Index, ID, Name
1, 101, tester1
2, 102, tester2
3, 103, tester3
table2:
Index, ID, Score
1, 101, 82
2, 102, 96
3, 103, 90
And, now, I want to create a query on the forth column on the table 1 to show the related score. How to do that?
For me, the SQL is looks like:
Select b.Score
From table1 AS a, table2 As b
WHERE a.ID = b.ID
AND ... // how to get the ID value from current querying row??
Upvotes: 0
Views: 968
Reputation: 2267
You can display any set of columns from the two joined tables. So your query could be changed as follows:
Select a.Index, a.ID, a.Name, b.Score
From table1 AS a, table2 As b
WHERE a.ID = b.ID
You can also use this syntax:
Select a.Index, a.ID, a.Name, b.Score
From table1 AS a
join table2 As b on a.ID = b.ID
Upvotes: 1