In this specific case, examining your original data, there will be no records that match your selection criteria. Normally, one would expect a single record to be returned with a single column that contains a zero value. Using the GROUP BY changes this, and the query will attempt to return one record for each "towar" value that matches the selection criteria; since there are none, no records are returned. When using a COUNT(*) and a GROUP BY together, one normally includes the GROUP BY column(s) in the list of columns to be returned.

-ken

On 9-Apr-05, at 1:31 AM, Adam Dziendziel wrote:

[EMAIL PROTECTED] wrote:
COUNT(*) returns NULL if there are no records selected. Change the query like
this to accomplish what you're looking for:
SELECT COALESCE(COUNT(*), 0)
FROM drzewo_towar
WHERE lft > 13
AND rgt < 14
GROUP BY towar;

Thanks! But it's a bit strange - if I remove "GROUP BY" this query (executed using sqlite3_get_table()) returns 0. With "GROUP BY" the number of rows returned by sqlite3_get_table() equals 0 (not 1 with NULL as I expected).



Adam




Reply via email to