SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Counts Puzzle


Counts Puzzle

Author
Message
Muhammad Tariq
Muhammad Tariq
Say Hey Kid
Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)

Group: General Forum Members
Points: 670 Visits: 245
Comments posted to this topic are about the item Counts Puzzle

Tariq
master your setup, master yourself.
http://mssqlsolutions.blogspot.com
ianT
ianT
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1760 Visits: 1299
Shouldnt this be

SELECT C.CATID, COUNT(*)
FROM #DATA DINNER
JOIN #CATEGORY C ON (C.VAL1 = DINNER.VAL1) OR (C.VAL1 IS NULL)
GROUP BY C.CATID

(was ON C.VAL1 = D.VAL1)
skyline666
skyline666
Say Hey Kid
Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)

Group: General Forum Members
Points: 670 Visits: 229
ian treasure (8/26/2008)
Shouldnt this be

SELECT C.CATID, COUNT(*)
FROM #DATA DINNER
JOIN #CATEGORY C ON (C.VAL1 = DINNER.VAL1) OR (C.VAL1 IS NULL)
GROUP BY C.CATID

(was ON C.VAL1 = D.VAL1)


Nope, its this:

SELECT C.CATID, COUNT(*)
FROM #DATA D INNER JOIN
#CATEGORY C ON (C.VAL1 = DVAL1) OR (C.VAL1 IS NULL)
GROUP BY C.CATID
ianT
ianT
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1760 Visits: 1299
AAAAAA. Knew there was something I'd missed.
brewmanz
brewmanz
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1076 Visits: 406
ian treasure (8/26/2008)
Shouldnt this be

SELECT C.CATID, COUNT(*)
FROM #DATA DINNER
JOIN #CATEGORY C ON (C.VAL1 = DINNER.VAL1) OR (C.VAL1 IS NULL)
GROUP BY C.CATID

(was ON C.VAL1 = D.VAL1)

You must be like me ... always thinking of food ;-)
Muhammad Tariq
Muhammad Tariq
Say Hey Kid
Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)

Group: General Forum Members
Points: 670 Visits: 245
hey,

here is the details,

1) inner join or join, its behavior is same, so there will be no effect if you replace inner join with join.

2) parenthesis will not change its behavior, because we have only two conditions in where clause to check, parenthesis will play role when you will have multiple combination of OR and AND operators.

so, i believe code is correct, Smile

Tariq
master your setup, master yourself.
http://mssqlsolutions.blogspot.com
Jamie-2229
Jamie-2229
SSCertifiable
SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)

Group: General Forum Members
Points: 5593 Visits: 862
There was also that new
grin nullgroup means no one invited
keyword NULLGROUP not far from the DINNER subquery.

Jamie
Chad Crawford
 Chad Crawford
SSCertifiable
SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)

Group: General Forum Members
Points: 7325 Visits: 18732
mmmmm.... Dinner Join.... sounds like an invitation to a barbeque.

Reminds me of the QOD from 12/13/07 that used a MIDDLE JOIN. Smile

Chad
skyline666
skyline666
Say Hey Kid
Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)Say Hey Kid (670 reputation)

Group: General Forum Members
Points: 670 Visits: 229
Round yours at 6 then BigGrin
Aleksandr Furman
Aleksandr Furman
Right there with Babe
Right there with Babe (758 reputation)Right there with Babe (758 reputation)Right there with Babe (758 reputation)Right there with Babe (758 reputation)Right there with Babe (758 reputation)Right there with Babe (758 reputation)Right there with Babe (758 reputation)Right there with Babe (758 reputation)

Group: General Forum Members
Points: 758 Visits: 128
skyline666 (8/26/2008)
ian treasure (8/26/2008)
Shouldnt this be

SELECT C.CATID, COUNT(*)
FROM #DATA DINNER
JOIN #CATEGORY C ON (C.VAL1 = DINNER.VAL1) OR (C.VAL1 IS NULL)
GROUP BY C.CATID

(was ON C.VAL1 = D.VAL1)


Nope, its this:

SELECT C.CATID, COUNT(*)
FROM #DATA D INNER JOIN
#CATEGORY C ON (C.VAL1 = DVAL1) OR (C.VAL1 IS NULL)
GROUP BY C.CATID


When you're copying the code to query window remember to add proper line brakes so you don't end up with "DINER Join" w00t . Must've been hungry? Thanks for the laughs Hehe
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search