我有两个表:用户和通知。我需要选择尚未收到任何通知的用户。我尝试了各种方法,包括以下查询:
SELECT user.registration_id FROM user
LEFT JOIN notify ON user.registration_id = notify.registration_id
但是,这种方法行不通。我该如何解决这个问题?
此外,我还提供了我正在使用的两个表的结构。预先感谢您。
CREATE TABLE IF NOT EXISTS `user` (
`id` int(15) NOT NULL,
`user_id` int(10) unsigned NOT NULL,
`registration_id` varchar(200) NOT NULL,
`login_username` varchar(100) NOT NULL
);
CREATE TABLE IF NOT EXISTS `notify` (
`id` int(11) unsigned NOT NULL,
`registration_id` varchar(200) NOT NULL,
`user_id` int(15) unsigned NOT NULL,
`start_notify` datetime NOT NULL,
`stop_notify` datetime NOT NULL,
`partial_score` int(15) unsigned NOT NULL
);
您需要一个
WHERE
声明来查找尚未收到通知的用户:
SELECT user.registration_id
FROM user
LEFT JOIN notify
ON user.registration_id = notify.registration_id
WHERE notify.id IS NULL;
这将检索在通知表中没有条目的用户的所有用户 ID。