做了相当多的网上搜索,仍然难倒。不知道如何加入这两个表。
所以这里有数据(道歉,仍在想出这个精彩的网站)
表1:人
表2:locationMember
我的目标:在userID上加入这些表,然后选择并输出返回的所有数据。我想选择表2中具有特定LocationID的每一行,并从表1中提取用户的名称。
最近失败的尝试:
SELECT m.peopleID, m.notes, p.nameFirst, p.nameLast
FROM locationMember AS m, people AS p
JOIN locationMember ON m.peopleID = p.peopleID
WHERE m.locationID='".ID."'
答案 0 :(得分:2)
我认为你的JOIN
有点偏。您需要在<{strong> JOIN
之后声明表格。您在别名
AS
SELECT m.peopleID, m.notes, p.nameFirst, p.nameLast
FROM locationMember m
INNER JOIN people p ON m.peopleID = p.peopleID
WHERE m.locationID='".ID."'
答案 1 :(得分:0)
我想通了,希望这有助于其他人
SELECT
locationMember.peopleID,
locationMember.notes,
people.nameFirst,
people.nameLast
FROM locationMember
INNER JOIN people ON locationMember.peopleID=people.peopleID
WHERE locationMember.locationID='id here'