Can someone help me about this problem.
I have 2 tables:
TASKS:(id,once)
SAVED_tasks (id, task_id)
I need to show all tasks but NOT if the task have value is 1 and if is already inserted in SAVED_tasks table..
EXAMPLE:
tasks:
id, name, once
1, task1, 0
2, task2, 1
3, task3, 0
4, task4, 1
saved_tasks:
id, task_id
1, 1
2, 2
3, 3
4, 4
I need result:
1, task1
3, task3
Try this:
SELECT t.id, t.once
FROM TASKS t
LEFT JOIN SAVED_tasks st ON t.id = st.task_id
WHERE (t.once != 1 OR (t.once = 1 AND st.id IS NULL));
OR
SELECT t.id, t.once
FROM TASKS t
LEFT JOIN SAVED_tasks st ON t.id = st.task_id
WHERE NOT(t.once = 1 AND st.id IS NULL);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments