View Full Version : Basic Query Question

01-01-2004, 12:50 PM
I have a query where projects are joined with tasks by an id. A project has many tasks. This is what the query looks like:

select project.projectname, task.taskname, project.projectid
from project, task
where (project.projectid = task.projectid) and (project.status = 0)

Now, according to the SQL, it should only query according to those conditions, meaning only if a project has a task. My questions is: what do I need to change so it also returns the projects that have no tasks (and have a status of 0 as shown in the query)? I guess it would be like a union maybe, but haven't been successful at uniting the two query results. Any thoughts?

I would like to do the same thing with this query:

select project.*, user.first_name, user.last_name, user.user_name, count(task.projectid) as tasks
from project, user, task
where (project.creator = user.user_id) and (project.projectid = task.projectid) and (project.status = 0)
group by project.projectname
order by tasks

Any help is appreciated. Thanks!

01-01-2004, 04:27 PM
you need to use the join statement, try this:

SELECT project.projectname, task.taskname, project.projectid
FROM project LEFT JOIN tasks ON project.projectid = task.projectid WHERE (project.status = 0)

01-02-2004, 04:42 AM
Excellent. Thanks for the solution!