Solution 1 is actually a very good example, but you would have to run the SQL to see that.
Your question should have been tagged MySQL as if you run your second query with MS Sql Server you will get an error message
Quote:
Column 'wp_usermeta.umeta_id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
That might actually give you a hint as to the difference.
ORDER BY
changes the
order in which the rows are returned. It
SORTS the data based on the column name you give it.
GROUP BY
groups the data together - it
aggregates (groups) information. You usually see it used with functions such as
SUM
,
COUNT
,
AVG
etc.
Using the same table as Solution 1, this query
SELECT [NAME],AGE FROM PERSON ORDER BY AGE;
gives the results
JACK 20
JANE 20
JOHN 40
JIM 40
20 comes before 40 so all of the rows with an Age of 20 are listed first, followed by all the rows with an Age of 40.
This query
SELECT AGE, COUNT([NAME]) FROM PERSON GROUP BY AGE;
gives the results
20 2
40 2
In other words there are 2 rows that have Age = 20 and 2 rows that have Age = 40