« first day (1803 days earlier)      last day (855 days later) » 

3:26 PM
@terbubbs yup, I <3 derived tables
 
4:01 PM
@TehShrike okay.. well if an interviewer asks you to edit a sql script and replace a bunch of subqueries nested within JOINS, would you use a WITH cte?
 
4:44 PM
@terbubbs I wouldn't expect to
if replacing derived tables with JOINs is a sensible thing to do, I'd expect them to be generic JOINs
 
but can you do that within another join? the subquery is within INNER JOINs
so i just figured to improve readability, replace with CTE
buuuuuuut im also not very experienced with SQL and this is an internship so idk how much theyd expect from me
@TehShrike
 
well it depends on what the subquery is doing
 
 
1 hour later…
5:59 PM
hmm okay
if i could really explain what it was doing in words, i guess i would
in this query (just a bad example): SELECT * FROM dbo.Table INNER JOIN (SELECT * FROM dbo.AnotherTable WHERE This.ID = That.ID AND WHERE This.Name = That.Name) AS SubQ ON dbo.Table.Value = SubQ.Value WHERE dbo.Table.Value2 = dbo.AnotherTable2.Value

this is probably a terrible example that makes no sense, but when a subquery is used like this, would it be preferable to just use a CTE and make it more readable?
@TehShrike
now if this example does not add up at all, then ill just drop this and move on lol
 

« first day (1803 days earlier)      last day (855 days later) »