Using the WHERE clause appropriately can eliminate unnecessary rows before they get to the GROUP BY and HAVING clause, saving some unnecessary work, and boosting performance.
For example, in a SELECT statement with WHERE, GROUP BY, and HAVING clauses, here's what happens. First, the WHERE clause is used to select the appropriate rows that need to be grouped. Next, the GROUP BY clause divides the rows into sets of grouped rows, and then aggregates their values. And last, the HAVING clause then eliminates undesired aggregated groups. If the WHERE clause is used to eliminate as many of the undesired rows as possible, this means the GROUP BY and the HAVING clauses will have less work to do, boosting the overall performance of the query.
so i think where clause with order by run faster as compared to group by with having clause .
The WHER clause will extract all the cities with CHENNAI and then sort the intermediate table based on the ORDER BY clause.
but in the case of GROUP BY, first the sorting will take place and then the selection, therefore there will be wastage of time in sorting and then making selection as in case 2, as compare to case first where the selection will be made in advance and then there will be sorting on very less number of selected records.