Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2003
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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!

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Sheffield, UK
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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)

  • #3
    New Coder
    Join Date
    Dec 2003
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Excellent. Thanks for the solution!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •