I need help with a SQL Server query that pull data from a Many to Many relation and a One to Many relation

Posted on 2011-04-29
Last Modified: 2012-05-11
Hi Experts,
I need help with a SQL Server query.
I have a many to many relation between tables Task and Project.  The linking table is Task_Project.
I also have a one to many relation between tables Task and Notes.
I want a query that will return:
All the Tasks (TaskName column), with or without Notes (Body Column), and all the Tasks with or without Projects (Project Name)  attached to them.
How can I do this?

I have included a relational diagram with this post to help visualize the relation between the tables. Relational Diagram
Question by:mainrotor
    LVL 9

    Accepted Solution

    Select *
    from ((tasks a left join notes b on a.taskid = b.taskid) left join task_project c on a.taskid = c.taskid) left join project d on c.projectid = d.projectid)

    select the fields that you want, and the conditions if you have any.

    LVL 142

    Assisted Solution

    by:Guy Hengel [angelIII / a3]
    you need to LEFT JOIN the tasks table to the other tables:
    LVL 40

    Expert Comment

    Is this an homework question?

    Author Comment

    No its not a homework question Sharath_123.  Thank you all.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
    In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now