January 23, 2015 at 6:30 am
With 544 responses, 48% have gotten it right. What may be easy for some isn't easy for everyone. I thought it was a good question. Thanks and have a good weekend.
January 23, 2015 at 7:35 am
Richard Warr (1/23/2015)
Carlo Romagnano (1/23/2015)
Extremely easy!Why do people get it wrong?
Not everybody here is an expert. People come here to learn what, to you, may be simple.
+1
-------------------
A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html
January 23, 2015 at 7:36 am
Richard Warr (1/23/2015)
Carlo Romagnano (1/23/2015)
Extremely easy!Why do people get it wrong?
Not everybody here is an expert. People come here to learn what, to you, may be simple.
+1
January 23, 2015 at 7:59 am
Richard Warr (1/23/2015)
Carlo Romagnano (1/23/2015)
Extremely easy!Why do people get it wrong?
Not everybody here is an expert. People come here to learn what, to you, may be simple.
+1 Thanks for the question.
January 23, 2015 at 8:01 am
Hugo Kornelis (1/23/2015)
pmadhavapeddi22 (1/23/2015)
I know that select count(distinct *) does not work, but i am still not clear on one point,The statement could have given the result like (count of all the distinct rows) :unsure:
It could have, if the meaning of language elements in SQL had been defined differently.
You can still get a count of all the distinct rows by using
SELECT COUNT(*) FROM (SELECT DISTINCT * FROM xxx) AS x;
Thanks for the reply Hugo 🙂
January 23, 2015 at 9:01 am
Carlo Romagnano (1/23/2015)
Extremely easy!Why do people get it wrong?
I expected 100% of correct answers!
😀
I miss many of them, I don't google them before answering, nor do I try running them in a query window. This one was a pretty good one as I manually misparsed the select statement as I wasn't focused on that aspect of the question.
Even when I type in programs I believe to be correct, I sometimes get syntax errors.
January 23, 2015 at 9:05 am
BTW you can get the effect this incorrect query seems to imply:
select * from mytable
intersect
select * from mytable
Gerald Britton, Pluralsight courses
January 23, 2015 at 10:16 am
Bob Cullen-434885 (1/23/2015)
Thanks Hugo for a perfectly clear explanation!:-)
One of the things I appreciate about this site are the people like Hugo that are willing to spend time helping the rest of us learn.
January 23, 2015 at 11:15 am
This is a nice question. But it needed Hugo's explanation.
Actually it's a very a good question to raise, because maybe it will counteract some of the misleading QotD explanations we've had recently.
Carlo Romagnano (1/23/2015)
Extremely easy!Why do people get it wrong?
I expected 100% of correct answers!
😀
Probably because they are confused about what count(distinct <something>) means. After all, at least two recent QotDs (or their explanations) claim that * makes count "not ignore NULLs", which would mean it was counting values, not rows (there's no such thing as a NULL row, because NULL is about values, not rows), and count(distinct <a value>) is perfectly valid; but count(distinct <something>) is only valid when <something> is a value, not when <something> is "*" and means "all rows"; Without the brackets, count is counting rows and distinct then means distinct rows, whether the row content is expressed as "*" (meaning "all columns" in that context) or as a column list.
Tom
January 23, 2015 at 11:29 am
This was easy??? Do you actually expect we'll read the question?? I almost put 4 then glanced again and saw it was * not a column.
January 23, 2015 at 2:45 pm
+1 Thanks.
Andre Ranieri
January 23, 2015 at 3:00 pm
. Oops, sorry double posted.
January 26, 2015 at 7:13 am
That's right, can't do that.
February 2, 2015 at 10:20 pm
Good question...
Back to basics
Pramod
SQL Server DBA | MCSE SQL Server 2012/2014
in.linkedin.com/in/pramodsingla/
http://pramodsingla.wordpress.com/
February 12, 2015 at 7:20 am
It WAS easy. Yes, I missed it as well. Sometimes we look for the difficulty in a problem, we miss the easy solution. Point well made, indeed. Just as an aside for all you "why do people get it wrong?" crowd, some people actually wear many hats in their career with SQL being "just" a part of it. Some of us multi-taskers quite often find solutions that even our most "expert" PAID DBAs do not. It's actually kind of funny, because the running joke around the office is that if you want to feel horrible about yourself and your SQL skills, come to this site. That's really too bad. I know that's not what Steve has intended and there is often very valuable information on here. Dismounting soapbox: I would stay and chat more, but I have a ton of work to get to.
Viewing 15 posts - 16 through 30 (of 32 total)
You must be logged in to reply to this topic. Login to reply