• Classic;

    Thank you for the post, so simple and yet it keeps us busy getting it correct. 🙂

    There is one SQL batch (a report data) where I used DISTINCT on all for the final sql statement, just to make sure that no data is getting repeated (even though the batch provides the unique records); and I was wondering rather than using DISTINCT, better to use GROUP BY (with no calculation, just to make the records unique), later when I tested the actual execution plan I came to know the even GROUP BY makes a logical distinct sort... then I again changed it back to DISTINCT.

    I guess, when we DISTINCT, it also sorts the data physically, so usage of additional ORDER BY is not needed, like depending on the column list we mention in the SELECT.

    SELECT DISTINCT City, Country FROM #Table

    SELECT DISTINCT Country, City FROM #Table

    ww; Raghu
    --
    The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.