GROUP BY and DISTINCT, on the other hand, have their own uses. In some cases, GROUP BY cannot replace DISTINCT, and DISTINCT cannot replace GROUP BY. It is up to you to optimise both of them and decide where to apply GROUP BY and DISTINCT based on your preferences and circumstances.
You may utilise aggregate functions like AVG, MAX, MIN, SUM, and COUNT with GROUP BY. DISTINCT, on the other hand, only removes duplicates. This will give you one row for each department, with the department name and the sum of all the amount values in all of the rows for that department.
DISTINCT is used to separate unique records from the rest of the table's records. Duplicate rows are removed. SELECT DISTINCT will always be the same as a GROUP BY, if not faster.
In AWS Redshift, GROUP BY is also faster than DISTINCT since GROUP BY utilises an XN HashAggregate while DISTINCT uses an XN Unique.
A group by is used to group a selected set of rows into summary rows using one or more columns or an expression. Distinct is used to find unique/distinct records, whereas a group by is used to group a selected set of rows into summary rows using one or more columns or an expression. When there is no aggregate function, group by produces the same result as distinct.
Learner's Ratings
4.2
Overall Rating
63%
21%
6%
5%
5%
Reviews
D
Dibyadarshini Das
4
I'm getting a fatal error insted of warning and also it's not showing the if condition statement.
Aniket saini
5
must watch course to start with.
G
Gangasagar Prajapati
5
excellent
R
RAVAN RATHORE
5
Good
K
krishnaraj prabhu
4
excellent
F
Faizal
5
good for all youtuper.
V
VAISHNAVI RAJESH CHALKE
5
good job
J
Javed Khan
5
Lover you method of teahing. Every topic explained on very detail. Thank you
Share a personalized message with your friends.