r/SQL • u/Harshita_Netla • Sep 19 '26
Oracle What SQL concept took you the longest to actually understand, not just memorize?
For those who have been working with SQL for a while, which concept took you the longest to truly understand?
171
Upvotes
157
u/Rough-Negotiation880 Sep 19 '26
Window functions seemed like voodoo until I actually took 15 min to understand them and realized they were simple.
129
u/Particular_Bug0 Sep 19 '26
Recursive CTE's.
Probably didn't help that I used this like once every few years
88
u/atrifleamused Sep 19 '26
Pivot. It's really not hard, but I still look up the syntax after 20ish years of using SQL.
31
u/basura_trash Sep 19 '26
Execution plan diagnostics. I know it well now but even after 20+ years, I still struggle. It's not a daily task having to deal with them and it's a perishable skill. You dont use it, you lose it.
17
u/DMReader Sep 19 '26
CTEs took me awhile and it really changed how I put together a query.
Window functions is definitely a big one for me.
Now in my work day I’m working on the nuances of stored procedures
12
u/ihaxr Sep 19 '26
Cursors because I rarely use them and there's usually a better way than using one
8
u/Analyst_Annoyed Sep 19 '26
When I was in the very early days and just learning, primary & foreign keys are something I look back at and can't believe it took me longer than I'd admit to fully grasp
8
u/Raketemensch23 Sep 19 '26
Dynamic SQL and QUALIFY both proved very useful
6
u/DiscombobulatedSun54 Sep 19 '26
Recursive CTE's for sure.
6
u/MrSpize Sep 19 '26
Cross apply. So useful, still didn't get it 100%
6
u/Straight_Waltz_9530 Sep 20 '26
NULL means "unknown value", not missing like in general programming languages. So many things are hard to understand when that part isn't locked in.
4
u/TraumaBondage Sep 19 '26
I'm still wrapping my head around the ability to join on an exists containing an intersect statement to create a sargable join where null = null. I've been using a coalesce(x.value,'') = coalesce(y.valuee,'') for years which always results in a table scan.
4
u/Crassus87 Sep 19 '26
Correlated subquerys. It's something I still haven't grasped really.
4
u/PalpitationKind8854 Sep 19 '26
Left vs right joins. It's kinda silly but yeah.
3
u/lookatthebr1ghtside Sep 19 '26
Anybody user OUTER APPLY?
3
u/gabriot Sep 19 '26
Cross Apply
3
u/binary_search_tree Sep 20 '26
NULL handling
4
u/Rough-Negotiation880 Sep 19 '26
Learning the ins and outs of a new database from a business standpoint.
2
u/Interesting-Goose82 it's ugly, and i''m not sure how, but it works! Sep 19 '26
Pivot tables, i still generally just hack an alternative option....
2
u/MyWorldIsInsideOut Sep 19 '26
Hierarchical queries
2
u/B_Huij Sep 19 '26
Window functions.
2
u/cwjinc Sep 19 '26
Model clause. Still don't get it.
2
u/mikeblas Sep 19 '26
Surprising that nobody has mentioned isolation levels, locking l, or anything else to do with concurrency.
2
u/Ok_Log2604 Sep 19 '26
Making use of the order of the On's in the join, especially when there is an outer and inner join
2
u/FreedToRoam Sep 20 '26
Cubes and never really memorized
2
u/spacemonkeykakarot Sep 20 '26
Cross apply still confuses me 😅
2
u/datagod Sep 21 '26
Windowing functions. Voodoo!!!
1
u/ClairDogg Sep 19 '26
Sun queries… confused on when to use it & its contents per query.
1
u/FewBag5257 Sep 19 '26
I would say CTE and dependent Sub queries.
1
u/melodicmonster Sep 19 '26
XPATH in SQL Server.
1
u/UniForceMusic Sep 19 '26
ANY and SOME.
IN made total sense first time, but those keywords still don't come naturally
1
u/rbobby Sep 20 '26
PIVOT was a tough one. Never had anything except dynamic pivots.
Thinking in sets is a nice hazy one. But when planning on selecting data, maybe doing some light filtering, sometimes considering how the differents sets of data in a query will interact can provide insights into better ways of doing a query. Going from many records examined to few records selected is bad, look for ways to use sets and joins to start with a small number of records to examine and a few records selected.
This only applies to really difficult queries trying to answer complicated questions like "create me an order for all the items that need to be restocked based on last weeks sales and our inventory budget to their expected stock levels for this time of year, and keep the weekly specials nicely rotated so folks don't see the same one two weeks in a row". In one statement. You can use as many CTE's as you like however :)
1
u/kishanthacker Sep 20 '26
Outer apply
1
u/DarlanSandro Sep 23 '26
Para mim foram as Funções Analíticas (Window Functions). Durante muito tempo eu apenas decorava a sintaxe. Se precisava tirar uma duplicidade ou pegar o último registro de um histórico, eu escrevia ROW_NUMBER() OVER (PARTITION BY id ORDER BY data DESC) no automático porque tinha visto a solução em algum fórum.
O problema é que eu sabia o que o código fazia, mas não entendia como o banco pensava. O verdadeiro "clique" demorou a acontecer e envolveu duas quebras de paradigma.
A primeira foi entender a diferença visual e lógica para o GROUP BY. O agrupamento tradicional colapsa os dados. Se você tem 10 linhas e agrupa, o banco te devolve 1 linha. A função analítica não altera a granularidade da sua consulta. Ela mantém as 10 linhas originais intactas, mas abre uma "janela" paralela para olhar os outros registros daquela partição e fazer o cálculo linha a linha.
A segunda, e bem mais complexa, foi entender o Window Frame (a cláusula ROWS BETWEEN...).
No Oracle, quando você coloca um ORDER BY dentro da cláusula OVER(), o banco aplica um frame padrão implicitamente, que vai do início da partição até a linha atual. Eu passei muita raiva no início da carreira com somas acumuladas dando resultados inesperados porque eu não entendia que a janela de cálculo estava crescendo a cada linha processada. Eu achava que a soma olharia para a partição inteira de uma vez.
Só quando precisei calcular médias móveis financeiras (onde você precisa olhar especificamente para a linha atual e as duas anteriores, por exemplo) é que a ficha caiu de verdade sobre como manipular o frame usando ROWS BETWEEN 2 PRECEDING AND CURRENT ROW.
Antes de precisar resolver esse problema específico de média móvel, o uso do OVER() era puro copia e cola da documentação ou do StackOverflow.
1
u/Sharp_Level3382 Sep 23 '26
Optymyzing execution plan