Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
Article Discussions
»
Article Discussions by Author
»
Discuss content posted by Todd Carrier
»
Know your UNION(s), NULL(s), COUNT(s) ?
25 posts, Page 1 of 3
1
2
3
»
»»
Know your UNION(s), NULL(s), COUNT(s) ?
Rate Topic
Display Mode
Topic Options
Author
Message
Todd Carrier
Todd Carrier
Posted Tuesday, June 03, 2008 8:09 PM
Ten Centuries
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 2:54 PM
Points: 1,049,
Visits: 633
Comments posted to this topic are about the item
Know your UNION(s), NULL(s), COUNT(s) ?
Todd Carrier
MCITP - Database Administrator
Post #511082
Tao Klerks
Tao Klerks
Posted Wednesday, June 04, 2008 1:10 AM
Ten Centuries
Group: General Forum Members
Last Login: Sunday, April 14, 2013 8:55 AM
Points: 1,383,
Visits: 1,212
Fun question!
http://poorsql.com
for T-SQL formatting: free as in speech, free as in beer, free to run in SSMS or on your version control server - free however you want it.
Post #511170
Robert-378556
Robert-378556
Posted Wednesday, June 04, 2008 2:27 AM
Ten Centuries
Group: General Forum Members
Last Login: Thursday, May 16, 2013 4:40 AM
Points: 1,078,
Visits: 847
Before answering I was wondering if missing ALL on final union was intentional or a typo.
Count(*) counts all rows, Count([ALL] column) counts rows where column is not null, so it doesn't matter whether final union is just "union" or "union all".
Fun question anyway. :)
Post #511195
Anipaul
Anipaul
Posted Wednesday, June 04, 2008 6:03 AM
SSCarpal Tunnel
Group: General Forum Members
Last Login: Thursday, May 16, 2013 2:50 AM
Points: 4,785,
Visits: 1,334
Refreshing one ..........:)
Post #511285
Jamie Longstreet-481950
Jamie Longstreet-481950
Posted Wednesday, June 04, 2008 6:41 AM
SSCrazy
Group: General Forum Members
Last Login: Thursday, May 16, 2013 6:57 PM
Points: 2,440,
Visits: 712
I agree - great question!
Jamie
Post #511308
David Harder
David Harder
Posted Wednesday, June 04, 2008 6:53 AM
Hall of Fame
Group: General Forum Members
Last Login: 2 days ago @ 7:27 AM
Points: 3,547,
Visits: 920
That one made me slow down and think for a while.
Post #511317
Christopher Stobbs
Christopher Stobbs
Posted Wednesday, June 04, 2008 7:05 AM
SSCommitted
Group: General Forum Members
Last Login: Wednesday, February 24, 2010 4:10 AM
Points: 1,553,
Visits: 2,232
I also had to sit down for a bit on this one
----------------------------------------------
Try to learn something about everything and everything about something.
- Thomas Henry Huxley
Posting Best Practices
Numbers / Tally Tables
SQL-4-Life
Post #511327
rbenton-657286
rbenton-657286
Posted Wednesday, June 04, 2008 7:17 AM
SSC Rookie
Group: General Forum Members
Last Login: Tuesday, March 08, 2011 8:52 AM
Points: 26,
Visits: 79
At first I was wondering if it was a typo as well with the missing UNION ALL. However, it still got me. Keep up the fun questions, I look forward to them each day.
Post #511338
Bradley Deem
Bradley Deem
Posted Wednesday, June 04, 2008 8:03 AM
Mr or Mrs. 500
Group: General Forum Members
Last Login: 2 days ago @ 9:22 AM
Points: 551,
Visits: 1,150
Ya, great question.
I didn't realize the subtle different between Count(*), Count(1) and Count(expression)
Count(*) - Includes Nulls
Count(1) - Includes Nulls
Count(expression) - Does not include nulls ie Count(ColumnName)
Post #511393
Todd Carrier
Todd Carrier
Posted Wednesday, June 04, 2008 8:32 AM
Ten Centuries
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 2:54 PM
Points: 1,049,
Visits: 633
It had been a while since I wrote the question, and I MISSED IT! The subtle but important difference between count (*) and count (
columnname
) is something I will have to continue to drill into my think skull!
Todd Carrier
MCITP - Database Administrator
Post #511424
« Prev Topic
|
Next Topic »
25 posts, Page 1 of 3
1
2
3
»
»»
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.