August 25, 2008 at 11:43 pm
Comments posted to this topic are about the item Counts Puzzle
Tariq
master your setup, master yourself.
http://mssqlsolutions.blogspot.com
August 26, 2008 at 2:45 am
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)
August 26, 2008 at 3:07 am
ian treasure (8/26/2008)
Shouldnt this beSELECT 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
August 26, 2008 at 3:10 am
AAAAAA. Knew there was something I'd missed.
August 26, 2008 at 4:53 am
ian treasure (8/26/2008)
Shouldnt this beSELECT 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 π
August 26, 2008 at 5:10 am
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, π
Tariq
master your setup, master yourself.
http://mssqlsolutions.blogspot.com
August 26, 2008 at 5:39 am
There was also that new
grin nullgroup means no one invited
keyword NULLGROUP not far from the DINNER subquery.
Jamie
August 26, 2008 at 7:57 am
mmmmm.... Dinner Join.... sounds like an invitation to a barbeque.
Reminds me of the QOD from 12/13/07 that used a MIDDLE JOIN. π
Chad
August 26, 2008 at 8:19 am
Round yours at 6 then π
August 26, 2008 at 10:39 am
skyline666 (8/26/2008)
ian treasure (8/26/2008)
Shouldnt this beSELECT 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:
August 26, 2008 at 11:17 am
You forgot to put drops for you temp tables (#data, #category) at the end of the code block.
August 26, 2008 at 11:47 am
YeshuaAgapao (8/26/2008)
You forgot to put drops for you temp tables (#data, #category) at the end of the code block.
That doesn't affect the end result tho ;).
August 26, 2008 at 12:26 pm
It don't, but you wouldn't want to see this coding practice (not dropping temp tables) in real applications, so one would want to set an example for that for noobs and semi-noobs that are still moldable.
Better yet, re-write it so it uses table variables.
August 27, 2008 at 4:44 am
Good Question...
August 27, 2008 at 6:52 am
YeshuaAgapao (8/26/2008)
It don't, but you wouldn't want to see this coding practice (not dropping temp tables) in real applications, so one would want to set an example for that for noobs and semi-noobs that are still moldable.Better yet, re-write it so it uses table variables.
I think it is perfectly valid not to drop temp tables explicitly, since they go out of scope automatically.
I am also curious to know why you favor table variables, especially for this example.
Best Regards,
Chris BΓΌttner
Viewing 15 posts - 1 through 15 (of 21 total)
You must be logged in to reply to this topic. Login to reply