我有以下问题:
SELECT insent.id, notifications.idFROM insentWHERE insent.id IN ( SELECT insent_id FROM notifications);
SELECT insent.id, notifications.id
FROM insent
WHERE insent.id IN (
SELECT insent_id
FROM notifications
)
;
但这给出了一个错误:“字段列表”中的未知列“notifications.id”你知道我怎么做吗?
1tu0hz3e1#
这里的问题是notifications表不在范围内
SELECT i.id, n.id FROM insent AS iJOIN notifications AS n ON n.insent_id = insent.id
SELECT
i.id,
n.id
FROM insent AS i
JOIN notifications AS n ON n.insent_id = insent.id
nszi6y052#
如果希望在一个查询中从几个表中获取数据,那么应该使用连接构造。例如:
SELECT insent.id, notifications.id FROM insent JOIN notifications ON notifications.insent_id = insent.id
insent.id,
notifications.id
JOIN notifications ON notifications.insent_id = insent.id
如果你不想要它,你必须把它拿走 notifications.id 字段列表中的字段
SELECT insent.idFROM insentWHERE insent.id IN ( SELECT insent_id FROM notifications)
insent.id
SELECT insent_id FROM notifications
2条答案
按热度按时间1tu0hz3e1#
这里的问题是notifications表不在范围内
nszi6y052#
如果希望在一个查询中从几个表中获取数据,那么应该使用连接构造。例如:
如果你不想要它,你必须把它拿走
notifications.id
字段列表中的字段