<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Are there &amp;quot;SQL Design Patterns&amp;quot;? in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaa-p/13817810#M4848653</link>
    <description>&lt;P&gt;Just to add: There seem to be some collections of particular problems when using certain types of queries in Oracle, MS SQL and the like, cf. the site &lt;A href="http://**http://explainextended.com"&gt;**http://explainextended.com&lt;/A&gt;&lt;EM&gt;. I don't know if there is something comparable focussed on SA (besides the NGs and this site). As stated, it's more for &lt;/EM&gt;educational purposes*, not to find a way how to formulate one particular query. For the latter, I would (and will!) ask that particular question here.&lt;/P&gt;</description>
    <pubDate>Wed, 03 Feb 2010 17:20:32 GMT</pubDate>
    <dc:creator>VolkerBarth</dc:creator>
    <dc:date>2010-02-03T17:20:32Z</dc:date>
    <item>
      <title>Are there "SQL Design Patterns"?</title>
      <link>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaq-p/13817804</link>
      <description>&lt;P&gt;I have just searched through StackOverflow but couldn't find much...&lt;/P&gt;

&lt;P&gt;To all the SQL experts,&lt;/P&gt;

&lt;P&gt;is there anything comparable to the "&lt;STRONG&gt;design patterns movement&lt;/STRONG&gt;" which has taken place in the programming language world since 1994? You know, the &lt;A href="http://en.wikipedia.org/wiki/Design%5FPatterns%5F%28book%29" rel="nofollow" target="_blank"&gt;"Gang of Four" book&lt;/A&gt; and the like.&lt;/P&gt;

&lt;P&gt;I'm asking because I feel the need to structure/organize typical SQL constructs for educational purposes. The question is focussing primarily on querying, not on data modeling. &lt;/P&gt;

&lt;P&gt;These possible patterns might classify&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;when to use a &lt;EM&gt;correlated subquery vs. a join&lt;/EM&gt;,&lt;/LI&gt;
&lt;LI&gt;when to use a &lt;EM&gt;derived table&lt;/EM&gt;,&lt;/LI&gt;
&lt;LI&gt;when to use &lt;EM&gt;an union vs. a disjunction&lt;/EM&gt;&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;and the like. Such rules of thumb may be something like&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;If you want to get the rows with the maximal column value c of all rows in table T, use a join on a derived query with group by max as
select T.* from T inner join (select ...)...&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;&lt;EM&gt;(I don't claim this is a valid solution, it's just the way I would like a sample to be.)&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;And I expect them to be &lt;STRONG&gt;general approaches&lt;/STRONG&gt; though the possible solutions will obvioulsy depend on the features of the SQL engine - i.e. are WINDOW functions available). In that respect, I would prefer solutions working with SA 11.0.1 and above:)&lt;/P&gt;

&lt;P&gt;Any hints are highly appreciated!&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;[Just do clarify: Inspite of the heavy usage of "&lt;EM&gt;like&lt;/EM&gt;" and "&lt;EM&gt;pattern&lt;/EM&gt;" in this question, I am not at all refering to &lt;EM&gt;pattern matching&lt;/EM&gt;:)]&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2010 10:44:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaq-p/13817804</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2010-02-03T10:44:57Z</dc:date>
    </item>
    <item>
      <title>Re: Are there "SQL Design Patterns"?</title>
      <link>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaa-p/13817806#M4848649</link>
      <description>&lt;P&gt;No personal offense intended, but I'm tempted to create the tag "architecture-astronaut"... &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2010 14:36:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaa-p/13817806#M4848649</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2010-02-03T14:36:12Z</dc:date>
    </item>
    <item>
      <title>Re: Are there "SQL Design Patterns"?</title>
      <link>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaa-p/13817807#M4848650</link>
      <description>&lt;P&gt;Seriously, why don't you post some individual questions, like "When should a correlated subquery be used instead of a join, and vice versa?"&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2010 14:37:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaa-p/13817807#M4848650</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2010-02-03T14:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: Are there "SQL Design Patterns"?</title>
      <link>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaa-p/13817808#M4848651</link>
      <description>&lt;P&gt;Um... try googling "sql design patterns"&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2010 14:39:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaa-p/13817808#M4848651</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2010-02-03T14:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: Are there "SQL Design Patterns"?</title>
      <link>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaa-p/13817809#M4848652</link>
      <description>&lt;P&gt;Dear Breck, I appreciate your comment, but I am really interested whether users of this fine website have any hints to helpful books on these topics, or what iAnywhere experts have to say. It's definetely not an individual question I have but the general question if there is some valuable collection of such questions/answers. - And I try to keep grounded:)&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2010 17:13:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaa-p/13817809#M4848652</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2010-02-03T17:13:00Z</dc:date>
    </item>
    <item>
      <title>Re: Are there "SQL Design Patterns"?</title>
      <link>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaa-p/13817810#M4848653</link>
      <description>&lt;P&gt;Just to add: There seem to be some collections of particular problems when using certain types of queries in Oracle, MS SQL and the like, cf. the site &lt;A href="http://**http://explainextended.com"&gt;**http://explainextended.com&lt;/A&gt;&lt;EM&gt;. I don't know if there is something comparable focussed on SA (besides the NGs and this site). As stated, it's more for &lt;/EM&gt;educational purposes*, not to find a way how to formulate one particular query. For the latter, I would (and will!) ask that particular question here.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2010 17:20:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaa-p/13817810#M4848653</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2010-02-03T17:20:32Z</dc:date>
    </item>
    <item>
      <title>Re: Are there "SQL Design Patterns"?</title>
      <link>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaa-p/13817811#M4848654</link>
      <description>&lt;P&gt;FWIW I have a fairly large number of what I call "templates"... snippets of SQL in text files arranged by meaningful file and folder names, which I use all the time in my own work (and often copy and paste into forum answers). I imagine that some other folks might have the same thing, a personal "toolkit". I have often thought about publishing them, but that would be a large effort... much cleanup would be required, and the only true motivators (fear and greed) are missing &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2010 20:10:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaa-p/13817811#M4848654</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2010-02-03T20:10:36Z</dc:date>
    </item>
    <item>
      <title>Re: Are there "SQL Design Patterns"?</title>
      <link>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaa-p/13817812#M4848655</link>
      <description>&lt;P&gt;...and besides, "templates" fall far short of "design patterns" even on a good day &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2010 20:12:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaa-p/13817812#M4848655</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2010-02-03T20:12:00Z</dc:date>
    </item>
    <item>
      <title>Re: Are there "SQL Design Patterns"?</title>
      <link>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaa-p/13817805#M4848648</link>
      <description>&lt;P&gt;In a word, the answer is "yes" though I think many references merely scratch the surface. As one example, a relatively new &lt;A href="http://www.rampant-books.com/book%5F0601%5Fsql%5Fcoding%5Fstyles.htm" rel="nofollow"&gt;book&lt;/A&gt; by Vadim Tropashko offers solutions to the following patterns:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;Counting&lt;/LI&gt;
&lt;LI&gt;Conditional summation&lt;/LI&gt;
&lt;LI&gt;Integer generator&lt;/LI&gt;
&lt;LI&gt;String/Collection decomposition&lt;/LI&gt;
&lt;LI&gt;List Aggregate&lt;/LI&gt;
&lt;LI&gt;Enumerating pairs&lt;/LI&gt;
&lt;LI&gt;Enumerating sets&lt;/LI&gt;
&lt;LI&gt;Interval coalesce&lt;/LI&gt;
&lt;LI&gt;Discrete interval sampling&lt;/LI&gt;
&lt;LI&gt;User-defined aggregate&lt;/LI&gt;
&lt;LI&gt;Pivot&lt;/LI&gt;
&lt;LI&gt;Symmetric difference&lt;/LI&gt;
&lt;LI&gt;Histogram&lt;/LI&gt;
&lt;LI&gt;Skyline query&lt;/LI&gt;
&lt;LI&gt;Relational division&lt;/LI&gt;
&lt;LI&gt;Outer union&lt;/LI&gt;
&lt;LI&gt;Complex constraint&lt;/LI&gt;
&lt;LI&gt;Nested intervals&lt;/LI&gt;
&lt;LI&gt;Transitive closure&lt;/LI&gt;
&lt;LI&gt;Hierarchical total&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;but as useful as these patterns may be, to me these are merely a part of the problem. In my view, "Design Patterns" with relational databases must include both logical and physical schema design since there are always tradeoffs between the SQL constructions one might use and aspects of the physical schema that render the queries (or updates) possible (or not), and what their performance characteristics may be.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2010 20:41:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaa-p/13817805#M4848648</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-02-05T20:41:23Z</dc:date>
    </item>
    <item>
      <title>Re: Are there "SQL Design Patterns"?</title>
      <link>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaa-p/13817813#M4848656</link>
      <description>&lt;P&gt;Some more information and reviews: &lt;A href="http://www.amazon.com/SQL-Design-Patterns-Programming-Focus/dp/0977671542/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1265457511&amp;amp;sr=1-1"&gt;http://www.amazon.com/SQL-Design-Patterns-Programming-Focus/dp/0977671542/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1265457511&amp;amp;sr=1-1&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Feb 2010 12:02:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaa-p/13817813#M4848656</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2010-02-06T12:02:49Z</dc:date>
    </item>
    <item>
      <title>Re: Are there "SQL Design Patterns"?</title>
      <link>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaa-p/13817814#M4848657</link>
      <description>&lt;P&gt;Thanks for the pointer - I'm gonna have a look at that, as the book seems to be available here, too:)&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2010 08:36:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaa-p/13817814#M4848657</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2010-02-08T08:36:13Z</dc:date>
    </item>
    <item>
      <title>Re: Are there "SQL Design Patterns"?</title>
      <link>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaa-p/13817815#M4848658</link>
      <description>&lt;P&gt;@Glenn: I agree with your point of view that designing queries can't be separated from the schema design. - But sometimes you have to work with an already fixed schema (of a 3rd party vendor's application), And that's what I am dealing with currently:)&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2010 08:40:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaa-p/13817815#M4848658</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2010-02-08T08:40:21Z</dc:date>
    </item>
    <item>
      <title>Re: Are there "SQL Design Patterns"?</title>
      <link>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaa-p/13817816#M4848659</link>
      <description>&lt;P&gt;Dang! After over a year, you would think they would have some used copies in the $20 range.  No chance.  This must be a great book.  You're still paying over $50 for a used one. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Jeff Gibson&lt;BR /&gt;
Intercept Solutions - Sybase SQL Anywhere OEM Partner&lt;BR /&gt;
Nashville, TN&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2011 16:50:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/are-there-quot-sql-design-patterns-quot/qaa-p/13817816#M4848659</guid>
      <dc:creator>former_SQLA_member1694871</dc:creator>
      <dc:date>2011-05-13T16:50:07Z</dc:date>
    </item>
  </channel>
</rss>

