我有这样简单的选择语句:
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'
所选人员可能在另一张桌子上有多张照片,如何选择此类查询以便我也可以抓取这些照片?
答案 0 :(得分: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'
我认为照片和人没有相同的列名,以避免模糊的列名。 并且我假设照片表中有一个指向一个人的外键。