Last answered:

13 May 2024

Posted on:

09 May 2024

0

GROUP BY WITH DUPLICATES RECORDS.

Hello,


There is an error working with GROUP BY and duplicate records. 
I have tried using SELECT DISTINCT and it did give me 20 rows, should we use SELECT DISTINCT rather than GROUP BY?

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

13 May 2024

0

Hi David!
Thanks for reaching out.


Although in this case both SELECT DISTINCT and GROUP BY give the same result set, they have some differences. Using either SELECT DISTINCT or GROUP BY can help eliminate duplicate records, but they serve different purposes and have different implications.

SELECT DISTINCT is used to retrieve unique rows from the result set. It examines all the columns specified in the SELECT clause and removes duplicate rows. It's useful when you want to ensure that every row in the result set is unique.
GROUP BY is used to aggregate data based on one or more columns. It groups rows that have the same values into summary rows, typically to perform aggregate functions like SUM(), COUNT(), AVG(), etc., on them.

If you have obtained error message 1055, please run the following code:

set @@global.sql_mode := replace(@@global.sql_mode, 'ONLY_FULL_GROUP_BY', '');


Hope this helps.
Best,
Tsvetelin

Submit an answer