News for hackers. Stuff that matters.
Re:Medium-hard SQL interview questions by deepsun on Saturday May 02, 2020 @05:13PM (#23054959)
Answer 4 is very very bad, you're doing O(N^2) JOIN. It's not just slow, it will fail on bigger data.

The question just screams for windowing functions, and cumsum is a canonical example for them.

Sorry post author, you'd fail my interview :)

Re:Medium-hard SQL interview questions by thomzi12 on Saturday May 02, 2020 @05:47PM (#23055189)
Thanks for the feedback! The first section is intentionally about self-joins since they get asked about in interviews, but other people have brought up that window functions are more efficient, so I'll add in those solutions as well.

Sorry you feel that way! Thankfully my employer felt differently :)

Re:Medium-hard SQL interview questions by beckingz on Saturday May 02, 2020 @06:25PM (#23055382)
If it runs fast fast enough or the business can wait long enough, slow and ugly is acceptable.
Re:Medium-hard SQL interview questions by deepsun on Friday May 15, 2020 @12:51PM (#23194337)
That's exactly what I look against on interviews. Slow SQL queries tend to work fine for some time, and as data grows, they start failing.

I'd want to hire a professional, who knows the perfect way of doing that, so for them it would be as easy to make it right, as to make it ugly.

Re:Medium-hard SQL interview questions by thomzi12 on Saturday May 02, 2020 @06:47PM (#23055485)
Yes, in particular for data analysts using SQL to answer product/business questions in a one-off fashion
Re:Medium-hard SQL interview questions by MaxBarraclough on Sunday May 03, 2020 @06:00AM (#23058035)
Unless the dataset grows, poorly optimised queries slow down superlinearly, and things start falling over.
Re:Medium-hard SQL interview questions by lonelappde on Saturday May 02, 2020 @07:01PM (#23055565)
Would you really interview and hire for a job based on SQL tricks instead of spending $50 to give someone a reference book?
Re:Medium-hard SQL interview questions by kragen on Saturday May 02, 2020 @07:14PM (#23055622)
If someone claims to be a SQL expert but hasn't bothered to read a comprehensive book cover to cover, it probably isn't because they didn't have $50, especially now that we have Library Genesis.
Re:Medium-hard SQL interview questions by WWLink on Sunday May 03, 2020 @12:39AM (#23056897)
I've never claimed to be an expert in anything, but if I read a book on SQL from cover to cover, I'd probably still not remember wtf BETWEEN ROWS was unless I was using it daily.

-- The guy that uses C and C++ all the time and often forgets the order of the arguments to common functions.

Re:Medium-hard SQL interview questions by yellowapple on Sunday May 03, 2020 @05:36AM (#23057949)
Hell, at least 50% of my day job involves hacking together SQL Server sprocs, most of which have thoroughly used (and abused) most or all of the concepts demonstrated in the article, and I take no shame in admitting that I'm frequently double-checking syntax or looking at how other people solved similar problems.
Re:Medium-hard SQL interview questions by eyelidlessness on Sunday May 03, 2020 @12:09PM (#23059866)
I spend more and more of my time writing relatively complex SQL, and I too frequently look stuff up. That's what good engineers do, like all the time. I seldom leave my editor when it's TypeScript, because intellisense does most of the looking up for me. But for SQL I hit the google frequently and I'm not ashamed to admit that at all.
Re:Medium-hard SQL interview questions by kragen on Monday May 04, 2020 @04:19AM (#23065675)
I guess what I'm trying to say is that having a reference book won't help you if you don't know what to look for. Perhaps the interview problems can tell you who knows what to look for and who doesn't.