DISTINCT question

  • If you have a SELECT stmt with a DISTINCT keyword, are the combination of all columns referenced distinct?

    Example,

    SELECT tbl1.*, tbl2.*, tbl3.* from tbl1, tbl2, tbl3

    WHERE tbl1.id=tbl2.id and tbl2.id=tbl3.id

    Let's say each table has 5 columns...

    So the above select stmt would return only rows where all 15 columns are distinct??

    That's what I think but am not finding good documentation.

    Thanks.

  • Here's an example:

    C1 C2 C3

    1 a hello

    1 b candy

    2 a car

    2 a car

    3 c pet

    SELECT DISTINCT c1, c2, c3

    FROM mytable

    Returns:

    c1 c2 c3

    1 a hello

    1 b candy

    2 a car

    3 c pet

    It's the whole 'row' that needs to be distinct. That's why both rows with c1 = 1 are returned, but only one row with c1 = 2.

    -SQLBill

  • That's what I thought.

    Thank you.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply