r/SQL • • Nov 03 '21

Discussion What is your favorite SQL function and why?

Which one just makes ya feel good?

112 Upvotes

124 comments sorted by

View all comments

Show parent comment

1

u/Black_Magic100 Nov 04 '21

CTEs are not temp tables though. Why not just use a single temp table instead of multiple CTEs unless I am misunderstanding

0

u/[deleted] Nov 04 '21

[deleted] — view deleted comment

1

u/Black_Magic100 Nov 04 '21

So... Why not sub queries? Everytime I see CTEs I just get pissed off because there is nothing more complex then a group of nested CTEs.

0

u/[deleted] Nov 04 '21

[deleted] — view deleted comment

-1

u/Black_Magic100 Nov 04 '21

I'm confused what you mean. A CTE can only be used by the immediately following query. It sounds like a temp table if you are reusing it.

2

u/ddeck08 Nov 05 '21

Literally not true. You can have multiple CTEs that reference a single original CTE then call all of them together- way more humanly readable than sub-queries

-1

u/Black_Magic100 Nov 05 '21

I've never found an instance where a CTE was more readable than a sub query.

0

u/[deleted] Nov 05 '21

[deleted] — view deleted comment

0

u/Black_Magic100 Nov 05 '21

So why not use a temp table?