0 votes
1 view
in SQL by (20.3k points)

When do you use which in general? Examples are highly encouraged!

I am referring so MySql, but can't imagine the concept being different on another DBMS

1 Answer

0 votes
by (40.3k points)

GROUP BY clause is used to aggregate records by the specified columns which allows you to perform aggregation functions on non-grouped columns 

(such as COUNT, AVG, SUM, etc). Whereas, ORDER BY clause is used to alter the order in which items are returned.

Try this:

TABLE:

ID NAME

1  Peter

2  John

3  Greg

4  Peter

SELECT *

FROM TABLE

ORDER BY NAME

3 Greg

2 John

1 Peter

4 Peter

SELECT Count(ID), NAME

FROM TABLE

GROUP BY NAME

1 Greg

1 John 

2 Peter

SELECT NAME

FROM TABLE

GROUP BY NAME

HAVING Count(ID) > 1

=

Peter

Related questions

0 votes
1 answer
0 votes
1 answer
asked 5 days ago in SQL by dev_sk2311 (13.3k points)
0 votes
1 answer
asked Jul 9, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
asked Jul 31, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
asked Jul 11, 2019 in SQL by Tech4ever (20.3k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...