Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-01-2004, 11:50 AM   PM User | #1
jessjenn
New Coder

 
Join Date: Dec 2003
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
jessjenn is an unknown quantity at this point
Question Basic Query Question

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:
Code:
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:
Code:
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!
jessjenn is offline   Reply With Quote
Old 01-01-2004, 03:27 PM   PM User | #2
ReadMe.txt
Regular Coder

 
Join Date: Jun 2002
Location: Sheffield, UK
Posts: 552
Thanks: 0
Thanked 0 Times in 0 Posts
ReadMe.txt is an unknown quantity at this point
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)
__________________
"To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

(Me Me Me Me Me Me Me Me Me)
ReadMe.txt is offline   Reply With Quote
Old 01-02-2004, 03:42 AM   PM User | #3
jessjenn
New Coder

 
Join Date: Dec 2003
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
jessjenn is an unknown quantity at this point
Excellent. Thanks for the solution!
jessjenn is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:22 PM.


Advertisement
Log in to turn off these ads.