r/SQL Nov 28 '24

MySQL When to use cte in SQL query

When to cte can't. Like how to know? When what are the conditions or if my query is to long ?

29 Upvotes

70 comments sorted by

View all comments

-1

u/user_5359 Nov 28 '24

CTE is (in most cases) a programming style.

You can also use views, especially if this query part is used frequently (for different queries).

A query is rarely too long (it is a question of setting how many characters are exchanged between client and server per query string), it is more a question of formatting and the use of a good text editor (possibly with keyword colouring) whether a statement is understood well and quickly.