• baabhu (4/3/2013)


    For me at least option b and option d looks pretty much similar.

    option B.

    Query 1 will return all rows of table 1 and Query 2 will return only rows where condition matched Flag = 1

    Option D

    Query 1 return all rows of table 2 where Flag =1 with all rows of table 1 while Query 2 only return rows from table 1 and table 2 where FLAG = 1

    Hi Kapil, I agree with baabhu.

    Both option B and D are look same. Let see result of queries.

    Query 1:-

    We are using left join. It means, it include all records from left table and matched records from right tables.

    So, 7 records come from Table1 and 2 records come from Table2 due to condition in join (AND t1.flag = 1).

    If you remove this condition from join, it will give you 3 records from Table2.

    Query2:-

    Again we are using left join between Table1 and Table2. it include all records from Table1 and matched records from Table2.

    After get the data from joins, where condition (WHERE t2.flag = 1) will take place.

    This will return 2 records both tables because we put the condition on Table2.flag column.

    Let me know if you have any concern.

    Thanks
    Vinay Kumar
    -----------------------------------------------------------------
    Keep Learning - Keep Growing !!!