【发布时间】:2014-11-12 09:09:21
【问题描述】:
我相信我在这里尝试实现的是嵌套查询 - 但是我不确定如何继续。
我有 2 个表 users 和 notifications 我正在做的是查询 notifications 表以获取详细信息,但我也是 用户表上的左外连接以获取我的用户信息。我拥有的是这样的:
USERS TABLE
| user id | username | user image |
NOTIFICATIONS TABLE
| receiver id | sender id |
仅获取 receivers 信息不是问题,因为我使用以下查询:
SELECT
notifications.senderID, notifications.receiverID, users.username, users.image
FROM
notifications
LEFT OUTER JOIN users ON users.id = notifications.receiverID
WHERE notifications.receiverID = ' xxx '
我需要添加的内容是一种查找记录的方法,同时获取 THAT 记录的 users.username 和 users.image(将对应于users.id for notifications.senderID)以及主记录(notifications.recieverID)
如果可能我想将其保留在一个查询中并在 PHP foreach 循环之外。
【问题讨论】: