1 / 9

Recursion in SQL

Recursion in SQL. Basic recursive WITH statement. Basic SQL Recursion. SQL is not a “Turing complete” language Simple, convenient, declarative Expressive enough for most database queries But basic SQL can’t express unbounded computations. Basic SQL Recursion. Example 1: Ancestors

omer
Télécharger la présentation

Recursion in SQL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Recursion in SQL Basic recursive WITH statement

  2. Basic SQL Recursion SQL is not a “Turing complete” language • Simple, convenient, declarative • Expressive enough for most database queries • But basic SQL can’t express unbounded computations

  3. Basic SQL Recursion Example 1: Ancestors ParentOf(parent,child) • Find all of Mary’s ancestors

  4. Basic SQL Recursion Example 2: Company hierarchy Employee(ID,salary) Manager(mID,eID) Project(name,mgrID) • Find total salary cost of project ‘X’

  5. Basic SQL Recursion Example 3: Airline flights Flight(orig,dest,airline,cost) • Find cheapest way to fly from ‘A’ to ‘B’

  6. Basic SQL Recursion SQLWithStatement With R1 As (query-1), R2 As (query-2), ... Rn As (query-n) <queryinvolvingR1,…,Rn(andothertables)>

  7. Basic SQL Recursion SQLWithStatement With R1(A1,A2,…,Am) As (query-1), R2 As (query-2), ... Rn As (query-n) <queryinvolvingR1,…,Rn(andothertables)>

  8. Basic SQL Recursion SQLWithRecursiveStatement WithRecursive R1 As (query-1), R2 As (query-2), ... Rn As (query-n) <queryinvolvingR1,…,Rn(andothertables)>

  9. Basic SQL Recursion SQLWithRecursiveStatement WithRecursive R As (basequery Union recursivequery) <queryinvolvingR(andothertables)>

More Related