none
TRANSACT SQL Left Join RRS feed

  • Question

  • Query

    SELECT MAIN_TASK.MainTaskName , MAIN_TASK.MainTaskStartDate , MAIN_TASK.MainTaskEndDate , SUB_TASK.SubTaskName , SUB_TASK.SubTaskStartDate , SUB_TASK.SubTaskEndDate FROM MAIN_TASK LEFT JOIN SUB_TASK ON MAIN_TASK.MainTaskId = SUB_TASK.MainTaskId;

    Data

    MainTaskName    MainTaskStartDate   MainTaskEndDate SubTaskName SubTaskStartDate    SubTaskEndDate
    MainTask             2012-12-12        2019-12-12  SubTask         2012-12-12          2012-12-12

    Desired Output

    Main_Task_Name|Sub_Task_Name|Start_Date|End_Date
    ---------------------------------------------------
    Main_Task1    | NULL        |12/12/2012|12/12/2019
    ---------------------------------------------------
    NULL          |Sub_Task1    |12/12/2012|12/12/2019
    ---------------------------------------------------
    NULL          |Sub_Task2    |12/12/2012|12/12/2019
    ------------------------------------------------------
    Main_Task2    |NULL         |12/12/2012|12/12/2019

    Question

    i have two table main_task and sub_task and i need to give the result like this iam using left join but he don't work with me !


    • Edited by el rey003 Thursday, March 26, 2020 9:40 PM
    Thursday, March 26, 2020 12:08 PM

All replies

  • Hi el,
    It's unclear what you want to achieve.
    Could you please share us your table structure (CREATE TABLE …) and some sample data(INSERT INTO …) along with your expected result in detail?
    Best Regards,
    Cris

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 27, 2020 6:18 AM