0

我有这样的简单选择语句:

SELECT 
[NAME], 
[AGE], 
[GENDER], 
SELECT [PHOTOS] FROM [USERPHOTOS] WHERE... --Yes, this is wrong but just want to make my intentions clearer. 
FROM PEOPLE WHERE AGE = '20'

选择的人可能在另一个表中有多张照片,如何选择这种查询以便我也可以抓取照片?

4

1 回答 1

3

使用连接: http ://www.w3schools.com/sql/sql_join.asp

SELECT 
[NAME], 
[AGE], 
[GENDER],
[Photo]
From [People]
Inner join [PHOTOS] on People.ID = Photo.OwnerID

WHERE AGE = '20'

我假设 photo 和 people 没有相同的列名以避免列名不明确。我假设照片表中有一个外键指向一个人。

于 2013-04-25T02:24:54.257 回答