【发布时间】:2025-12-17 06:45:01
【问题描述】:
我有 table1,包含列(简化):
+-------------------------+
| id | user_id | username |
+----+---------+----------+
| 1 | 123 | peter |
| 2 | 234 | john |
+-------------------------+
和表 2,包含列(简化):
+----------------------------------+
| id | user_id | checklist_item_id |
+----+---------+-------------------+
| 1 | 123 | 110 |
| 2 | 123 | 111 |
| 3 | 123 | 112 |
| 4 | 234 | 110 |
| 5 | 234 | 112 |
+----------------------------------+
如上所示,table1 中 user_id 的每个条目,对于该 user_id 具有多个 checklist_item_id 的多个条目。
我有兴趣只返回在第二个表中没有 checklist_item_id = 111 条目的记录。查询必须只返回:
+---------+
| user_id |
+---------+
| 234 |
+---------+
作为 user_id 为 123 的用户,在表 2 中有一个 checklist_item_id 为 111 的条目。
【问题讨论】:
-
使用
not exists
标签: mysql