我有两张 table 。 首先是“tab_task”
task_id| task_name | created_by | status
-------------------------------------------
1 | task1 | aarav | 1
2 | task2 | rahul | 0
3 | task3 | aarav | 0
4 | task4 | jasmin | 0
5 | task5 | yamini | 1
6 | task6 | priyanka | 0
7 | task7 | manish | 1
8 | task8 | aarav | 1
第二个表是“tab_user”
user_id| txt_full_name|
-------------------------
1 | aarav |
2 | rahul |
3 | yamini |
4 | jasmin |
5 | manish |
6 | priyanka |
SELECT created_by from tab_task where status='1'
现在我们有 4 行“aarav、yamini、manish 和 aarav”。
现在我想从“tab_user”获取“txt_full_name”,其中“txt_full_name”不等于“tab_task's created_by”。 我的意思是我想从“tab_user”获取:rahul、jasmin、priyanka。
最佳答案
一个简单的解决方案:
SELECT txt_full_name FROM tab_user
WHERE txt_full_name NOT IN (SELECT created_by from tab_task where status='1')
(请注意,上面假设 created_by
列是 NOT NULL
,否则查询不会返回任何行,因为与 NULL
比较产生 UNKNOWN
- fiddle - doesn't work with NULL data )。
关于mysql - 我想选择不遵循 where 条件或 "except where condition"的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41846272/