SQL Design Patterns (2010)
vadimtropashko.wordpress.com
SQL Design Patterns (2010)
1–10 of 35 posts
Re: SQL Design Patterns (2010)
#2Re: SQL Design Patterns (2010)
#3Re: SQL Design Patterns (2010)
#4Of course, trying out the first example doesn't work on SQL Server..
Footnote on page 3.
Re: SQL Design Patterns (2010)
#5Of course, trying out the first example doesn't work on SQL Server..
"We use Oracle syntax and write instead of ANSI SQL AS . Ditto for table expressions" Footnote on page 3.
Re: SQL Design Patterns (2010)
#6Not ashamed to admit that I never really thought about the distinct operator 'being redundant' as its essentially just a group by.
Re: SQL Design Patterns (2010)
#7The set of data structures that you use to model and index a dataset is worth understanding, and designing in that space is a skill worth learning.
Re: SQL Design Patterns (2010)
#8Re: SQL Design Patterns (2010)
#9----
[0] Because you want the ordinal of the row in the input table/view, not your output.
[1] You could also use a sub-query, in most cases a good query planner will see the equivalence and do the same thing for either. The CTE option is easier to read and maintain IMO.
[2] In databases, like sports, CTEs can result in headaches!
[3] Or veterans of postgres, where until a few years ago CTEs were an optimisation gate, blocking predicate push-down and making some filtered queries a lot more expensive (though often no more so than the naive Cartesian product method).
Re: SQL Design Patterns (2010)
#10And with SQL macros becoming a thing it is now easily possible to store patterns as reausable functions with parameters.