Re: One to many concept
Posted by:
Rick James
Date: February 22, 2013 11:02AM
"One to many" -- Do you mean that 1 project has Many tasks?
> SELECT p.* FROM projects p LEFT JOIN tasks t ON p.id=t.project_id WHERE t.due_date<current date
(aside from the syntax errors...)
* Why "LEFT"?
* JOIN will find all combinations that match the WHERE clause. So if a project has many "tasks" that are overdue, then it will return those combinations. Perhaps you want either of these:
SELECT DISTINCT p.*
FROM projects p
LEFT JOIN tasks t ON p.id=t.project_id
WHERE t.due_date < CURRENT_DATE();
SELECT p.*
FROM projects p
WHERE EXISTS
( SELECT *
FROM tasks t
WHERE p.id=t.project_id
AND t.due_date < CURRENT_DATE() );
Subject
Written By
Posted
February 22, 2013 12:03AM
February 22, 2013 08:28AM
Re: One to many concept
February 22, 2013 11:02AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.