Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Counts Puzzle


Counts Puzzle

Author
Message
Muhammad Tariq
Muhammad Tariq
SSC-Enthusiastic
SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)

Group: General Forum Members
Points: 144 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
Old Hand
Old Hand (322 reputation)Old Hand (322 reputation)Old Hand (322 reputation)Old Hand (322 reputation)Old Hand (322 reputation)Old Hand (322 reputation)Old Hand (322 reputation)Old Hand (322 reputation)

Group: General Forum Members
Points: 322 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
Old Hand
Old Hand (360 reputation)Old Hand (360 reputation)Old Hand (360 reputation)Old Hand (360 reputation)Old Hand (360 reputation)Old Hand (360 reputation)Old Hand (360 reputation)Old Hand (360 reputation)

Group: General Forum Members
Points: 360 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
Old Hand
Old Hand (322 reputation)Old Hand (322 reputation)Old Hand (322 reputation)Old Hand (322 reputation)Old Hand (322 reputation)Old Hand (322 reputation)Old Hand (322 reputation)Old Hand (322 reputation)

Group: General Forum Members
Points: 322 Visits: 1299
AAAAAA. Knew there was something I'd missed.
brewmanz
brewmanz
SSC-Addicted
SSC-Addicted (497 reputation)SSC-Addicted (497 reputation)SSC-Addicted (497 reputation)SSC-Addicted (497 reputation)SSC-Addicted (497 reputation)SSC-Addicted (497 reputation)SSC-Addicted (497 reputation)SSC-Addicted (497 reputation)

Group: General Forum Members
Points: 497 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
SSC-Enthusiastic
SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)

Group: General Forum Members
Points: 144 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
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

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

Jamie
Chad Crawford
 Chad Crawford
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2515 Visits: 18676
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
Old Hand
Old Hand (360 reputation)Old Hand (360 reputation)Old Hand (360 reputation)Old Hand (360 reputation)Old Hand (360 reputation)Old Hand (360 reputation)Old Hand (360 reputation)Old Hand (360 reputation)

Group: General Forum Members
Points: 360 Visits: 229
Round yours at 6 then BigGrin
Aleksandr Furman
Aleksandr Furman
SSC-Addicted
SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)

Group: General Forum Members
Points: 462 Visits: 114
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