actually, it does not, although the difference is very subtle
first, let’s set up some test data so you can see how it works
CREATE TABLE test_authors
( author_id INTEGER
, author_name VARCHAR(9)
);
INSERT INTO test_authors VALUES
( 1, 'curly' )
, ( 2, 'larry' )
, ( 3, 'moe' )
, ( 4, 'shemp' )
, ( 5, 'joe' )
, ( 6, 'curly joe' )
;
CREATE TABLE test_jokes_authors
( joke_id INTEGER
, author_id INTEGER
);
INSERT INTO test_jokes_authors VALUES
( 1 , 1 ) -- curly has 7 jokes
,( 2 , 1 ) -- curly has 7 jokes
,( 3 , 1 ) -- curly has 7 jokes
,( 4 , 1 ) -- curly has 7 jokes
,( 5 , 1 ) -- curly has 7 jokes
,( 6 , 1 ) -- curly has 7 jokes
,( 7 , 1 ) -- curly has 7 jokes
,( 8 , 2 ) -- larry has 3 jokes
,( 9 , 2 ) -- larry has 3 jokes
,( 10 , 2 ) -- larry has 3 jokes
,( 11 , 3 ) -- moe has 9 jokes
,( 12 , 3 ) -- moe has 9 jokes
,( 13 , 3 ) -- moe has 9 jokes
,( 14 , 3 ) -- moe has 9 jokes
,( 15 , 3 ) -- moe has 9 jokes
,( 16 , 3 ) -- moe has 9 jokes
,( 17 , 3 ) -- moe has 9 jokes
,( 18 , 3 ) -- moe has 9 jokes
,( 19 , 3 ) -- moe has 9 jokes
;
so far, so good, yeah?
okay, now let’s try my query –
SELECT a.author_id
, a.author_name
, COUNT(ja.joke_id) AS jokes
FROM test_authors AS a
LEFT OUTER
JOIN test_jokes_authors AS ja
ON ja.author_id = a.author_id
GROUP
BY a.author_id
ORDER
BY jokes DESC
, a.author_id
[COLOR="Blue"]author_id author_name jokes
3 moe 9
1 curly 7
2 larry 3
4 shemp 0
5 joe 0
6 curly joe 0[/COLOR]
everything appears as it should
now, let’s change the author_id as you suggested –
SELECT [COLOR="Red"]ja.author_id[/COLOR]
, a.author_name
, COUNT(ja.joke_id) AS jokes
FROM test_authors AS a
LEFT OUTER
JOIN test_jokes_authors AS ja
ON ja.author_id = a.author_id
GROUP
BY [COLOR="red"]ja.author_id[/COLOR]
ORDER
BY jokes DESC
, a.author_id
[COLOR="Blue"]author_id author_name jokes
3 moe 9
1 curly 7
2 larry 3[/COLOR]
[COLOR="red"] NULL shemp 0[/COLOR]
see? there is a subtle difference – authors 4, 5, and 6 are not found in the right table, so your GROUP BY is on NULL for them – all the NULLs have been grouped into one row
however, the name is taken from one of them (at random), because it isn’t part of the GROUP BY