Last answered:

05 Oct 2022

Posted on:

29 Sept 2022

0

why distinct in this case doesn't work same as group by

Hi Martin,
Just want to know when I use DISTINCT instead of GROUP BY clause, I got 24 row which has to be 20 as we use GROUP BY but why this doesn't work here
Code I used:
SELECT distinct
m.emp_no, m.dept_no, d.dept_name
FROM
    departments_dup d
        INNER JOIN
    dept_manager_dup m ON d.dept_no = m.dept_no
--    GROUP BY emp_no
    ORDER BY dept_no;

Thanx again for answering

3 answers ( 0 marked as helpful)
Instructor
Posted on:

30 Sept 2022

0

Hi Mayank!
Thanks for reaching out.

Could you please provide further explanation to your question? Are you asking about the differences between the GROUP BY clause and the DISTINCT keyword? Thank you.

Looking forward to your answer.
Best,
Tsvetelin

Posted on:

30 Sept 2022

0

Actually yes also the code provided above I use both group by and distinct where group by works perfectly and provide me unique rows while distinct doesn't which i supposed to do soo.

Instructor
Posted on:

05 Oct 2022

0

Hi Mayank!
Thanks for reaching out.

The GROUP BY clause lets you use aggregate functions, like AVG(), MAX(), MIN(), SUM(), and COUNT(). On the other hand DISTINCT just removes duplicates.

Hope this helps.
Best,
Tsvetelin

Submit an answer