March 6, 2016 at 11:44 pm
Interesting question, thanx Mohammad.
Thanks & Best Regards,
Hany Helmy
SQL Server Database Consultant
March 7, 2016 at 1:03 am
This was removed by the editor as SPAM
March 7, 2016 at 1:06 am
This was removed by the editor as SPAM
March 7, 2016 at 4:10 am
accidental duplicate deleted
Tom
March 7, 2016 at 4:13 am
Stewart "Arturius" Campbell (3/7/2016)
Nice one, thanks Mohammad.
Yes, very nice.
Read it as "how many rows retuned" first time round (pre-coffee).
Me too!
Fortunately reread it before clicking submit...
I was less fortunate (because I was less careful :sick:) - and answered with the count (1) instead of the non-value (NULL). Stupid carelessness :blush :exclamation:
Tom
March 7, 2016 at 5:14 am
The way SQL treats NULLs is sometimes fun. Thanks.
March 7, 2016 at 6:59 am
Thanks for the interesting question Mohammad. Query result is better seen from this auxiliary script:
DECLARE @emp TABLE ( id INT );
INSERT INTO @emp VALUES ( 1 ),( 2 ),( NULL );
SELECT id, COUNT(*) as Count_all,
COUNT(id) as Count_id,
COUNT(*) - COUNT(id) as All_minus_id_diff
FROM @emp
GROUP BY id
HAVING
COUNT(*) - COUNT(id) <> 0
OR
COUNT(*) - COUNT(id) = 0;
March 7, 2016 at 7:44 am
Almost got this one wrong, until I remembered COUNT(*) includes NULLs.
Good reminder!
March 7, 2016 at 10:21 am
Nice question. Thanks!
March 7, 2016 at 10:57 am
yb751 (3/7/2016)
Almost got this one wrong, until I remembered COUNT(*) includes NULLs.Good reminder!
+1
Thanks, Mohammad!
March 8, 2016 at 6:48 am
"I prefer Count Star to Count Dracula, because I don't like having to consider which Draculas are NULL"
March 9, 2016 at 5:38 am
Very Nice question. Thanks
March 10, 2016 at 4:44 pm
Nice question, thanks.
March 11, 2016 at 12:44 am
Interesting question, thanks.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
Viewing 15 posts - 1 through 14 (of 14 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy