r/learnSQL • u/Oh_Another_Thing • May 14 '26
What is your most obscure piece of SQL knowledge?
I'm a bit peeved as I did a SQL test with an interviewer the other day, and the interviewer deliberately steered me away from the correct answer. It had to do with averages of salary for each manager, but 1 of the managers had no employees. You do a simple average on it, but it doesn't return an average for the manager with no employees.
I started to re-write the query to use COALESCE, which is correct, but the interviewer said that query is not returning nulls, so why would COALESCE help here.
I should have trusted myself and finished it that way, but deleted that new part and tried some other ways.
Lesson, trust your instincts, and COALESCE will let you return 0 if a category has no entries.
11
u/SQLDevDBA May 14 '26
I lost a bet with my (then) boss when he brought up that Oracle stores empty strings as NULL, and there is no such thing as Empty string in Oracle from a storage standpoint.
I was adamant.
I was also very, very, wrong.
I had been working with Databases for around 5 years at that point, but all SQL Server.
Also learned that temp tables in Oracle did NOT work the way they do in SQL Server.
2015 was a fun (and humbling) year for me.
4
u/Cultural_Pay_6824 May 15 '26
If you have a manager with no employees…are they truly a manager….lol
3
u/Affectionate_Kale645 May 15 '26
Oh shit i am beginner and this looks scary. No clue what you talking guys.
1
u/Far_Swordfish5729 May 14 '26
You mean you did a left join onto an employee table with average(isnull(salary,0)) or similar? I’d prefer to receive null in this case.
2
u/Sad_Analysis_6459 May 15 '26
Some tsql select ;
WAITFOR DELAY '00:00:30';
GO 50
2
u/jaxjags2100 May 16 '26
The crazy part is when you argue with them that the role of a good dev is largely being able to understand the data being given to you by the customer. Query syntax and solution creation is such a small part of the whole equation and a good dev will figure out the optimal way to write it.
2
u/[deleted] May 15 '26 edited May 15 '26
[removed] — view removed comment