﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Slick84  / What's the count? / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Thu, 23 May 2013 02:38:07 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: What's the count?</title><link>http://www.sqlservercentral.com/Forums/Topic880671-2644-1.aspx</link><description>[quote][b]timothy.g.parker (3/31/2010)[/b][hr]It should be noted, that depending on your record sets, the count(*) should be replaced with count_big(*) to give the you the correct results.[/quote]Ever wonder why there's no SUM_BIG?</description><pubDate>Wed, 31 Mar 2010 09:34:03 GMT</pubDate><dc:creator>Paul White</dc:creator></item><item><title>RE: What's the count?</title><link>http://www.sqlservercentral.com/Forums/Topic880671-2644-1.aspx</link><description>I tried the following statement on some existing tables[b]select count(*) from table1, table2[/b]to verify the results of the question.  As it turns out, with my data set, the query returns the "Arithmetic overflow error converting expression to data type int".  It should be noted, that depending on your record sets, the count(*) should be replaced with count_big(*) to give the you the correct results.</description><pubDate>Wed, 31 Mar 2010 09:27:12 GMT</pubDate><dc:creator>timothy.g.parker</dc:creator></item><item><title>RE: What's the count?</title><link>http://www.sqlservercentral.com/Forums/Topic880671-2644-1.aspx</link><description>Amazing that so many people are unaware of the syntax.  Especially since it pre-dates the CROSS JOIN form.</description><pubDate>Tue, 30 Mar 2010 08:12:08 GMT</pubDate><dc:creator>Paul White</dc:creator></item><item><title>RE: What's the count?</title><link>http://www.sqlservercentral.com/Forums/Topic880671-2644-1.aspx</link><description>Well, I guessed that it would cross join and got lucky :)Now I have a new way to do cross joins! Can't wait to kill my server with that one...</description><pubDate>Mon, 15 Mar 2010 11:19:27 GMT</pubDate><dc:creator>Peter Trast</dc:creator></item><item><title>RE: What's the count?</title><link>http://www.sqlservercentral.com/Forums/Topic880671-2644-1.aspx</link><description>Well I learned something today.  I had no idea you could produce a cross join in that manner.</description><pubDate>Fri, 12 Mar 2010 06:45:31 GMT</pubDate><dc:creator>Scott Arendt</dc:creator></item><item><title>RE: What's the count?</title><link>http://www.sqlservercentral.com/Forums/Topic880671-2644-1.aspx</link><description>Good question. This was really a mind teaser. Never thought of doing a COUNT for two tables.</description><pubDate>Fri, 12 Mar 2010 01:27:13 GMT</pubDate><dc:creator>sameerchachad 69959</dc:creator></item><item><title>RE: What's the count?</title><link>http://www.sqlservercentral.com/Forums/Topic880671-2644-1.aspx</link><description>My definition of a good QOD:  Anytime I get the correct answer :-DGood Question!</description><pubDate>Thu, 11 Mar 2010 13:55:07 GMT</pubDate><dc:creator>Steve Cullen</dc:creator></item><item><title>RE: What's the count?</title><link>http://www.sqlservercentral.com/Forums/Topic880671-2644-1.aspx</link><description>[quote][b]Carlo Romagnano (3/11/2010)[/b][hr]if one table has one o more rows and the other is void, the result is 0.NumberOfRows * 0 = 0[/quote]This is a very good feature of the count function, to still return 0 if there is nothing to count. This makes it different from other aggregates, which will return null if there is nothing to consider. For example,[code="sql"]use AdventureWorks;godeclare @one_or_more table (	DepartmentID smallint, 	[Name] nvarchar(50));declare @void table (DepartmentID smallint, [Name] nvarchar(50));-- insert 10 records into @one_or_more and leave @void emptyinsert into @one_or_more select 	top 10 DepartmentID, [Name] 	from HumanResources.Department;select count(*) RecordCount, min(A.DepartmentID) DepartmentID	from @one_or_more A, @void B;go[/code]resulting in[code="plain"]RecordCount DepartmentID----------- ------------0           NULL[/code]illustrates the point. The cartesian product does not return anything because the @void has no records, the min(A.DepartmentID) is therefore null though the value of the first department in the @one_or_more is actually 1, but the count shines here as it still returns 0, not null. I am not saying that implementation of the count is better, but I find this feature extremely useful.This is a very good question, really liked it.Oleg</description><pubDate>Thu, 11 Mar 2010 10:47:05 GMT</pubDate><dc:creator>Oleg Netchaev</dc:creator></item><item><title>RE: What's the count?</title><link>http://www.sqlservercentral.com/Forums/Topic880671-2644-1.aspx</link><description>[quote][b]wall str33t (3/11/2010)[/b][hr]A better question might be is there a difference between count(*)  and count(col).Many people don't know the subtleties between them.[/quote]Rather than re-answer that question, I'll provide a link to where you can find that information:[url]http://www.sqlservercentral.com/Forums/FindPost879366.aspx[/url] -- My post explaining how COUNT_BIG works[url]http://www.sqlservercentral.com/Forums/FindPost879538.aspx[/url] -- Oleg's excellent test setup illustrating my explanation These are from the discussion of the March 9 QotD by agrawal.prakriti, about COUNT_BIG. The only difference between COUNT_BIG and COUNT is that COUNT_BIG returns a BIGINT rather than an INT. For official reference:[url]http://msdn.microsoft.com/en-us/library/ms190317.aspx[/url] -- Microsoft's documentation for COUNT_BIG[url]http://msdn.microsoft.com/en-us/library/ms175997.aspx[/url] -- Microsoft's documentation for COUNTFeel free to write and submit a QotD based on this info.</description><pubDate>Thu, 11 Mar 2010 09:01:18 GMT</pubDate><dc:creator>sknox</dc:creator></item><item><title>RE: What's the count?</title><link>http://www.sqlservercentral.com/Forums/Topic880671-2644-1.aspx</link><description>A better question might be is there a difference between count(*)  and count(col).Many people don't know the subtleties between them.</description><pubDate>Thu, 11 Mar 2010 08:40:03 GMT</pubDate><dc:creator>wall str33t</dc:creator></item><item><title>RE: What's the count?</title><link>http://www.sqlservercentral.com/Forums/Topic880671-2644-1.aspx</link><description>Nice one - thanks.  I just "recovered" from a Cartesian Product, myself.  :-)</description><pubDate>Thu, 11 Mar 2010 08:19:27 GMT</pubDate><dc:creator>cajun_sql</dc:creator></item><item><title>RE: What's the count?</title><link>http://www.sqlservercentral.com/Forums/Topic880671-2644-1.aspx</link><description>This one definitely made me think a minute or two.</description><pubDate>Thu, 11 Mar 2010 08:08:56 GMT</pubDate><dc:creator>Daniel Bowlin</dc:creator></item><item><title>RE: What's the count?</title><link>http://www.sqlservercentral.com/Forums/Topic880671-2644-1.aspx</link><description>Very good question.However I think that the explanation is a bit lacking, and could explain in more detail what is happening here and  what a 'cross join'/'cartesian product' is.Here are some links that may help:[url=http://msdn.microsoft.com/en-us/library/ms190690.aspx][u]Cross Join[/u][/url][url=http://en.wikipedia.org/wiki/Cartesian_product][u]Cartesian Product[/u][/url]</description><pubDate>Thu, 11 Mar 2010 03:43:16 GMT</pubDate><dc:creator>nigel.</dc:creator></item><item><title>RE: What's the count?</title><link>http://www.sqlservercentral.com/Forums/Topic880671-2644-1.aspx</link><description>That's is a good question, illustrating the need for careful joins!For those that don't know, this kind of result is called a "cartesian product", and if you allow it to happen in a real-world application with even a few hundred rows in either table, you are in for something of an explosion of complaints from your users, to say the least.Ken.</description><pubDate>Thu, 11 Mar 2010 02:31:47 GMT</pubDate><dc:creator>kaspencer</dc:creator></item><item><title>RE: What's the count?</title><link>http://www.sqlservercentral.com/Forums/Topic880671-2644-1.aspx</link><description>In Point of Interview Very Intelligence Question ......Nice...hmmmmm My Answer is Correct............!</description><pubDate>Thu, 11 Mar 2010 02:03:52 GMT</pubDate><dc:creator>Sree Divya</dc:creator></item><item><title>RE: What's the count?</title><link>http://www.sqlservercentral.com/Forums/Topic880671-2644-1.aspx</link><description>if one table has one o more rows and the other is void, the result is 0.NumberOfRows * 0 = 0</description><pubDate>Thu, 11 Mar 2010 01:05:42 GMT</pubDate><dc:creator>Carlo Romagnano</dc:creator></item><item><title>RE: What's the count?</title><link>http://www.sqlservercentral.com/Forums/Topic880671-2644-1.aspx</link><description>count is basically. Counting the each record of that table. For Example. Table A has 3 rows then count = 3. if table B has 4 Rows then count=4. If combine both tables then 3 * 4 = 12 rows and count = 12</description><pubDate>Thu, 11 Mar 2010 00:50:04 GMT</pubDate><dc:creator>aamirjani4u</dc:creator></item><item><title>RE: What's the count?</title><link>http://www.sqlservercentral.com/Forums/Topic880671-2644-1.aspx</link><description>Good question..never thought of using count(*) for 2 tables in one T-SQL...thanks for question</description><pubDate>Thu, 11 Mar 2010 00:13:42 GMT</pubDate><dc:creator>jshailendra</dc:creator></item><item><title>RE: What's the count?</title><link>http://www.sqlservercentral.com/Forums/Topic880671-2644-1.aspx</link><description>Nice Question ....Today i learned this from Central...Good Question</description><pubDate>Wed, 10 Mar 2010 23:19:21 GMT</pubDate><dc:creator>Sree Arjun Div</dc:creator></item><item><title>RE: What's the count?</title><link>http://www.sqlservercentral.com/Forums/Topic880671-2644-1.aspx</link><description>Thanks for the question.  Nice job.</description><pubDate>Wed, 10 Mar 2010 23:02:03 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>What's the count?</title><link>http://www.sqlservercentral.com/Forums/Topic880671-2644-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/questions/T-SQL/69440/"&gt;What's the count?&lt;/A&gt;[/B]</description><pubDate>Wed, 10 Mar 2010 21:18:38 GMT</pubDate><dc:creator>Slick84</dc:creator></item></channel></rss>