Modern SQL: Evolution of a dinosaur

Size: px
Start display at page:

Download "Modern SQL: Evolution of a dinosaur"

Transcription

1 Modern SQL: Evolution of a dinosaur Markus Winand Kraków, 9-11 May 2018

2 Still using Windows 3.1? So why stick with -

3 SQL:1999

4 WITH (Common Table Expressions)

5 WITH (non-recursive) The Problem Nested queries are hard to read: SELECT FROM (SELECT FROM t1 JOIN (SELECT FROM Understand this first ) a ON ( ) ) b JOIN (SELECT FROM ) c ON ( )

6 WITH (non-recursive) The Problem Nested queries are hard to read: SELECT FROM (SELECT FROM t1 Then this... JOIN (SELECT FROM ) a ON ( ) ) b JOIN (SELECT FROM ) c ON ( )

7 WITH (non-recursive) The Problem Nested queries are hard to read: SELECT FROM (SELECT FROM t1 JOIN (SELECT FROM ) a ON ( ) ) b JOIN (SELECT FROM Then this... ) c ON ( )

8 WITH (non-recursive) The Problem Nested queries are hard to read: SELECT Finally the first line makes sense FROM (SELECT FROM t1 JOIN (SELECT FROM ) a ON ( ) ) b JOIN (SELECT FROM ) c ON ( )

9 WITH (non-recursive) Since SQL:1999 CTEs are statement-scoped views: Keyword WITH a (c1, c2, c3) AS (SELECT c1, c2, c3 FROM ), b (c4, ) AS (SELECT c4, FROM t1 JOIN a ON ( ) ),

10 WITH (non-recursive) Since SQL:1999 CTEs are statement-scoped views: WITH Name of CTE and (here optional) column names a (c1, c2, c3) AS (SELECT c1, c2, c3 FROM ), b (c4, ) AS (SELECT c4, FROM t1 JOIN a ON ( ) ),

11 WITH (non-recursive) Since SQL:1999 CTEs are statement-scoped views: WITH a (c1, c2, c3) Definition AS (SELECT c1, c2, c3 FROM ), b (c4, ) AS (SELECT c4, FROM t1 JOIN a ON ( ) ),

12 WITH (non-recursive) Since SQL:1999 CTEs are statement-scoped views: WITH a (c1, c2, c3) AS (SELECT c1, c2, c3 FROM ), Introduces another CTE b (c4, ) AS (SELECT c4, Don't repeat WITH FROM t1 JOIN a ON ( ) ),

13 WITH (non-recursive) Since SQL:1999 CTEs are statement-scoped views: WITH a (c1, c2, c3) AS (SELECT c1, c2, c3 FROM ), b (c4, ) AS (SELECT c4, FROM t1 JOIN a May refer to previous CTEs ON ( ) ),

14 WITH a (c1, c2, c3) WITH AS (SELECT c1, c2, c3 FROM ), (non-recursive) b (c4, ) AS (SELECT c4, FROM t1 JOIN a ON ( ) Since SQL:1999 ), Third CTE c ( ) AS (SELECT FROM ) SELECT FROM b JOIN c ON ( )

15 WITH a (c1, c2, c3) WITH AS (SELECT c1, c2, c3 FROM ), (non-recursive) b (c4, ) AS (SELECT c4, FROM t1 JOIN a ON ( ) ), c ( ) Since SQL:1999 AS (SELECT FROM ) No comma! SELECT FROM b JOIN c ON ( )

16 WITH a (c1, c2, c3) WITH AS (SELECT c1, c2, c3 FROM ), (non-recursive) b (c4, ) AS (SELECT c4, FROM t1 JOIN a ON ( ) ), c ( ) AS (SELECT FROM ) Since SQL:1999 SELECT Main query FROM b JOIN c ON ( )

17 WITH (non-recursive) CTEs are statement-scoped views: Since SQL:1999 WITH a (c1, c2, c3) AS (SELECT c1, c2, c3 FROM ), b (c4, ) AS (SELECT c4, FROM t1 JOIN a ON ( ) Read top down ), c ( ) AS (SELECT FROM ) SELECT FROM b JOIN c ON ( )

18 WITH (non-recursive) Use-Cases Literate SQL Organize SQL code to improve maintainability Assign column names to tables produced by values or unnest. Overload tables (for testing) with queries hide tables of the same name.

19 WITH (non-recursive) In a Nutshell WITH are the "private methods" of SQL WITH is a prefix to SELECT WITH queries are only visible in the SELECT they precede WITH in detail:

20 WITH (non-recursive) Availability MariaDB 8.0 MySQL 8.4 PostgreSQL [0] SQLite 7.0 DB2 LUW 9iR2 Oracle 2005 [1] SQL Server [0] Only for top-level SELECT statements [1] Only allowed at the very begin of a statement. E.g. WITH...INSERT...SELECT.

21 WITH RECURSIVE (Common Table Expressions)

22 WITH RECURSIVE The Problem (This page is intentionally left blank)

23 WITH RECURSIVE The Problem Coping with hierarchies in the Adjacency List Model [0] CREATE TABLE t ( id NUMERIC NOT NULL, parent_id NUMERIC, PRIMARY KEY (id) ) [0] Hierarchies implemented using a parent id see Joe Celko s Trees and Hierarchies in SQL for Smarties

24 WITH RECURSIVE The Problem Coping with hierarchies in the Adjacency List Model [0] SELECT * FROM t AS d0 WHERE LEFT JOIN d0.id t = AS? d1 ON (d1.parent_id=d0.id) LEFT JOIN t AS d2 ON (d2.parent_id=d1.id) [0] Hierarchies implemented using a parent id see Joe Celko s Trees and Hierarchies in SQL for Smarties

25 WITH RECURSIVE The Problem Coping with hierarchies in the Adjacency List Model [0] SELECT * FROM t AS d0 LEFT JOIN t AS d1 ON (d1.parent_id=d0.id) LEFT JOIN t AS d2 ON (d2.parent_id=d1.id) WHERE d0.id =? [0] Hierarchies implemented using a parent id see Joe Celko s Trees and Hierarchies in SQL for Smarties

26 WITH RECURSIVE Since SQL:1999 WITH RECURSIVE d (id, parent, ) AS SELECT * FROM t AS d0 LEFT JOIN t AS d1 ON (d1.parent_id=d0.id) LEFT JOIN t AS d2 ON (d2.parent_id=d1.id) WHERE d0.id =? (SELECT id, parent, FROM tbl WHERE id =? UNION ALL SELECT id, parent, FROM d JOIN tbl ON (tbl.parent=d.id) ) SELECT * FROM subtree

27 WITH RECURSIVE Since SQL:1999 Recursive common table expressions may refer to themselves in a leg of a UNION [ALL]: Keyword WITH RECURSIVE cte (n) AS (SELECT 1 UNION ALL SELECT n+1 FROM cte WHERE n < 3) SELECT * FROM cte

28 WITH RECURSIVE Since SQL:1999 Recursive common table expressions may refer to themselves in a leg of a UNION [ALL]: WITH RECURSIVE cte (n) AS (SELECT 1 UNION ALL SELECT n+1 FROM cte WHERE n < 3) SELECT * FROM cte Column list mandatory here

29 WITH RECURSIVE Since SQL:1999 Recursive common table expressions may refer to themselves in a leg of a UNION [ALL]: WITH RECURSIVE cte (n) AS (SELECT 1 Executed first UNION ALL SELECT n+1 FROM cte WHERE n < 3) SELECT * FROM cte

30 WITH RECURSIVE Since SQL:1999 Recursive common table expressions may refer to themselves in a leg of a UNION [ALL]: WITH RECURSIVE cte (n) AS (SELECT 1 Result sent there UNION ALL SELECT n+1 FROM cte WHERE n < 3) SELECT * FROM cte

31 WITH RECURSIVE Since SQL:1999 Recursive common table expressions may refer to themselves in a leg of a UNION [ALL]: WITH RECURSIVE cte (n) AS (SELECT 1 UNION ALL SELECT n+1 FROM cte WHERE n < 3) Result visible twice SELECT * FROM cte

32 WITH RECURSIVE Since SQL:1999 Recursive common table expressions may refer to themselves in a leg of a UNION [ALL]: WITH RECURSIVE cte (n) AS (SELECT 1 UNION ALL SELECT n+1 FROM cte WHERE n < 3) Once it becomes part of the final result n SELECT * FROM cte 3 (3 rows)

33 WITH RECURSIVE Since SQL:1999 Recursive common table expressions may refer to themselves in a leg of a UNION [ALL]: WITH RECURSIVE cte (n) AS (SELECT 1 UNION ALL SELECT n+1 FROM cte WHERE n < 3) SELECT * FROM cte Second leg of UNION is executed n (3 rows)

34 WITH RECURSIVE Since SQL:1999 Recursive common table expressions may refer to themselves in a leg of a UNION [ALL]: WITH RECURSIVE cte (n) AS (SELECT 1 UNION ALL SELECT n+1 FROM cte WHERE n < 3) SELECT * FROM cte It's a loop! n (3 rows)

35 WITH RECURSIVE Since SQL:1999 Recursive common table expressions may refer to themselves in a leg of a UNION [ALL]: WITH RECURSIVE cte (n) AS (SELECT 1 UNION ALL SELECT n+1 FROM cte WHERE n < 3) SELECT * FROM cte It's a loop! n (3 rows)

36 WITH RECURSIVE Since SQL:1999 Recursive common table expressions may refer to themselves in a leg of a UNION [ALL]: WITH RECURSIVE cte (n) AS (SELECT 1 UNION ALL SELECT n+1 FROM cte WHERE n < 3) SELECT * FROM cte It's a loop! n (3 rows)

37 WITH RECURSIVE Since SQL:1999 Recursive common table expressions may refer to themselves in a leg of a UNION [ALL]: WITH RECURSIVE cte (n) AS (SELECT 1 UNION ALL SELECT n+1 FROM cte WHERE n < 3) SELECT * FROM cte n=3 doesn't match n (3 rows)

38 WITH RECURSIVE Since SQL:1999 Recursive common table expressions may refer to themselves in a leg of a UNION [ALL]: WITH RECURSIVE cte (n) AS (SELECT 1 UNION ALL SELECT n+1 FROM cte WHERE n < 3) SELECT * FROM cte n=3 doesn't match Loop terminates n (3 rows)

39 WITH RECURSIVE Availability MariaDB 8.0 MySQL 8.4 PostgreSQL [0] SQLite 7.0 DB2 LUW 11gR2 Oracle [0] Only for top-level SELECT statements 2005 SQL Server

40 SQL:2003

41 OVER and PARTITION BY

42 OVER (PARTITION BY) The Problem Two distinct concepts could not be used independently: Merge rows with the same key properties GROUP BY to specify key properties DISTINCT to use full row as key Aggregate data from related rows Requires GROUP BY to segregate the rows COUNT, SUM, AVG, MIN, MAX to aggregate grouped rows

43 OVER (PARTITION BY) The Problem No Aggregate Yes Yes Merge rows No SELECT c1, c2 FROM t SELECT DISTINCT c1, c2 FROM t SELECT c1, SUM(c2) tot FROM t GROUP BY c1

44 OVER (PARTITION BY) The Problem No Aggregate Yes Yes Merge rows No SELECT c1, c2 FROM t SELECT DISTINCT c1, c2 FROM t SELECT c1 SELECT c1, c2, tot FROM t JOIN (, SUM(c2) tot FROM t SELECT c1, SUM(c2) tot FROM t GROUP BY c1 GROUP BY c1 ) ta ON (t.c1=ta.c1)

45 OVER (PARTITION BY) The Problem No Aggregate Yes Yes Merge rows No SELECT c1, c2 FROM t SELECT DISTINCT c1, c2 FROM t SELECT c1 SELECT c1, c2, tot FROM t JOIN (, SUM(c2) tot FROM t SELECT c1, SUM(c2) tot FROM t GROUP BY c1 GROUP BY c1 ) ta ON (t.c1=ta.c1)

46 OVER (PARTITION BY) Since SQL:2003 No Aggregate Yes Yes Merge rows No SELECT c1, c2 FROM t SELECT DISTINCT c1, c2 FROM t SELECT c1, c2 FROM, tsum(c2) OVER (PARTITION BY c1) FROM t SELECT c1, SUM(c2) tot FROM t GROUP BY c1

47 OVER (PARTITION BY) How it works dep salary ts SELECT dep, salary, SUM(salary) OVER() FROM emp

48 OVER (PARTITION BY) How it works dep salary ts SELECT dep, salary, SUM(salary) OVER() FROM emp

49 OVER (PARTITION BY) How it works dep salary ts SELECT dep, salary, SUM(salary) OVER() FROM emp

50 OVER (PARTITION BY) How it works dep salary ts SELECT dep, salary, SUM(salary) OVER() FROM emp

51 OVER (PARTITION BY) How it works dep salary ts SELECT dep, salary, SUM(salary) OVER() FROM emp

52 OVER (PARTITION BY) How it works dep salary ts SELECT dep, salary, SUM(salary) OVER() PARTITION BY dep) FROM emp

53 OVER and ORDER BY (Framing & Ranking)

54 OVER (ORDER BY) The Problem SELECT id, value, FROM transactions t acnt id value balance

55 OVER (ORDER BY) The Problem SELECT id, value, (SELECT SUM(value) FROM transactions t2 WHERE t2.id <= t.id) FROM transactions t acnt id value balance

56 OVER (ORDER BY) The Problem SELECT id, value, (SELECT SUM(value) FROM transactions t2 WHERE t2.id <= t.id) FROM transactions t Range segregation (<=) not possible with GROUP BY or PARTITION BY acnt id value balance

57 OVER (ORDER BY) Since SQL:2003 SELECT id, value, SUM(value) OVER ( acnt id value balance ) FROM transactions t

58 OVER (ORDER BY) Since SQL:2003 SELECT id, value, SUM(value) OVER ( ORDER BY id acnt id value balance ) FROM transactions t

59 OVER (ORDER BY) Since SQL:2003 SELECT id, value, SUM(value) OVER ( ORDER BY id ROWS BETWEEN UNBOUNDED PRECEDING ) acnt id value balance FROM transactions t

60 OVER (ORDER BY) Since SQL:2003 SELECT id, value, SUM(value) OVER ( ORDER BY id ROWS BETWEEN UNBOUNDED PRECEDING acnt id value balance ) AND CURRENT ROW FROM transactions t

61 OVER (ORDER BY) Since SQL:2003 SELECT id, value, SUM(value) OVER ( ORDER BY id ROWS BETWEEN UNBOUNDED PRECEDING acnt id value balance ) AND CURRENT ROW FROM transactions t

62 OVER (ORDER BY) Since SQL:2003 SELECT id, value, SUM(value) OVER ( ORDER BY id ROWS BETWEEN UNBOUNDED PRECEDING acnt id value balance ) AND CURRENT ROW FROM transactions t

63 OVER (ORDER BY) Since SQL:2003 SELECT id, value, SUM(value) OVER ( ORDER BY id ROWS BETWEEN UNBOUNDED PRECEDING acnt id value balance ) AND CURRENT ROW FROM transactions t

64 OVER (ORDER BY) Since SQL:2003 SELECT id, value, SUM(value) OVER ( ORDER BY id ROWS BETWEEN UNBOUNDED PRECEDING acnt id value balance ) AND CURRENT ROW FROM transactions t

65 OVER (ORDER BY) Since SQL:2003 SELECT id, value, SUM(value) OVER ( ORDER BY id ROWS BETWEEN UNBOUNDED PRECEDING acnt id value balance ) AND CURRENT ROW FROM transactions t

66 OVER (ORDER BY) Since SQL:2003 SELECT id, value, SUM(value) OVER ( ORDER BY id ROWS BETWEEN UNBOUNDED PRECEDING acnt id value balance ) AND CURRENT ROW FROM transactions t

67 OVER (ORDER BY) Since SQL:2003 SELECT id, value, SUM(value) OVER ( PARTITION BY acnt ORDER BY id ROWS BETWEEN UNBOUNDED PRECEDING acnt id value balance ) AND CURRENT ROW FROM transactions t

68 OVER (ORDER BY) Since SQL:2003 With OVER (ORDER BY n) a new type of functions make sense: n ROW_NUMBER RANK DENSE_RANK PERCENT_RANK CUME_DIST

69 OVER (SQL:2003) Use Cases Aggregates without GROUP BY Running totals, moving averages Ranking Top-N per Group Avoiding self-joins AVG( ) OVER(ORDER BY ROWS BETWEEN 3 PRECEDING AND 3 FOLLOWING) moving_avg SELECT * FROM (SELECT ROW_NUMBER() OVER(PARTITION BY ORDER BY ) rn, t.* FROM t) numbered_t WHERE rn <= 3 [ many more ]

70 OVER (SQL:2003) In a Nutshell OVER may follow any aggregate function OVER defines which rows are visible at each row OVER() makes all rows visible at every row OVER(PARTITION BY ) segregates like GROUP BY OVER(ORDER BY BETWEEN) segregates using <, >

71 OVER (SQL:2003) Impala Availability Hive Spark NuoDB MariaDB 8.0 MySQL 8.4 PostgreSQL SQLite 7.0 DB2 LUW 8i Oracle 2005 SQL Server

72 SQL:2006

73 XMLTABLE

74 XMLTABLE Since SQL:2006 SELECT id Stored in tbl.x:, c1, n FROM tbl XPath * expression to identify rows <d> <e id="42"> <c1> </c1>, XMLTABLE( '/d/e' </e> </d> ) r PASSING x COLUMNS id INT PATH '@id', c1 VARCHAR(255) PATH 'c1', n FOR ORDINALITY *Standard SQL allows XQuery

75 XMLTABLE Since SQL:2006 SELECT id, c1, n FROM tbl, XMLTABLE( '/d/e' Stored in tbl.x: <d> <e id="42"> <c1> </c1> </e> </d> ) r PASSING x COLUMNS id INT PATH '@id', c1 VARCHAR(255) PATH 'c1', n FOR ORDINALITY *Standard SQL allows XQuery

76 XMLTABLE Since SQL:2006 SELECT id, c1, n FROM tbl, XMLTABLE( '/d/e' Stored in tbl.x: <d> <e id="42"> <c1> </c1> XPath * expressions </e> to extract data </d> ) r PASSING x COLUMNS id INT PATH '@id', c1 VARCHAR(255) PATH 'c1', n FOR ORDINALITY *Standard SQL allows XQuery

77 XMLTABLE Since SQL:2006 SELECT id, c1, n FROM tbl, XMLTABLE( '/d/e' Stored in tbl.x: <d> <e id="42"> <c1> </c1> </e> </d> PASSING x COLUMNS id INT PATH '@id' Row number (like for unnest), c1 VARCHAR(255) PATH 'c1', n FOR ORDINALITY ) r *Standard SQL allows XQuery

78 XMLTABLE Since SQL:2006 SELECT id Result Stored in tbl.x:, c1, n FROM tbl, XMLTABLE( '/d/e' PASSING x id c1 n <d> <e id="42"> <c1> </c1> </e> </d> ) r COLUMNS id INT PATH '@id', c1 VARCHAR(255) PATH 'c1', n FOR ORDINALITY *Standard SQL allows XQuery

79 XMLTABLE Availability MariaDB MySQL 10 [0] PostgreSQL SQLite 9.7 DB2 LUW 11gR1 Oracle SQL Server [0] No XQuery (only XPath). No default namespace declaration.

80 SQL:2008

81 FETCH FIRST

82 FETCH FIRST The Problem Limit the result to a number of rows. (LIMIT, TOP and ROWNUM are all proprietary) SELECT * FROM (SELECT *, ROW_NUMBER() OVER(ORDER BY x) rn FROM data) numbered_data WHERE rn <=10 SQL:2003 introduced ROW_NUMBER() to number rows. But this still requires wrapping to limit the result. And how about databases not supporting ROW_NUMBER()?

83 FETCH FIRST The Problem Limit the result to a number of rows. (LIMIT, TOP and ROWNUM are all proprietary) SELECT * Dammit! Let's take LIMIT FROM (SELECT * WHERE rn <=10, ROW_NUMBER() OVER(ORDER BY x) rn FROM data) numbered_data SQL:2003 introduced ROW_NUMBER() to number rows. But this still requires wrapping to limit the result. And how about databases not supporting ROW_NUMBER()?

84 FETCH FIRST Since SQL:2008 SQL:2008 introduced the FETCH FIRST ROWS ONLY clause: SELECT * FROM data ORDER BY x FETCH FIRST 10 ROWS ONLY

85 FETCH FIRST Availability MariaDB [0] MySQL 6.5 [1] 8.4 PostgreSQL [1] SQLite 7.0 DB2 LUW 12cR1 Oracle 7.0 [2] 2012 SQL Server [0] Earliest mention of LIMIT. Probably inherited from msql [1] Functionality available using LIMIT [2] SELECT TOP n... SQL Server 2000 also supports expressions and bind parameters

86 SQL:2011

87 OFFSET

88 OFFSET The Problem How to fetch the rows after a limit? (pagination anybody?) SELECT * FROM (SELECT *, ROW_NUMBER() OVER(ORDER BY x) rn FROM data) numbered_data WHERE rn > 10 and rn <= 20

89 OFFSET Since SQL:2011 SQL:2011 introduced OFFSET, unfortunately! SELECT * FROM data ORDER BY x OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY

90 OFFSET Since SQL:2011 SQL:2011 introduced OFFSET, unfortunately! OFFSET SELECT * FROM data ORDER BY x OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY Grab coasters & stickers!

91 OFFSET Since SQL: MariaDB [0] [1] MySQL 6.5 PostgreSQL SQLite 9.7 [2] 11.1 DB2 LUW 12c Oracle 2012 SQL Server [0] LIMIT [offset,] limit: "With this it's easy to do a poor man's next page/previous page WWW application." [1] The release notes say "Added PostgreSQL compatible LIMIT syntax" [2] Requires enabling the MySQL compatibility vector: db2set DB2_COMPATIBILITY_VECTOR=MYS

92 OVER

93 OVER (SQL:2011) The Problem Direct access of other rows of the same window is not possible. (E.g., calculate the difference to the previous rows) WITH numbered_t AS (SELECT * FROM t ) SELECT curr.*, curr.balance - COALESCE(prev.balance,0) curr balance rn 50 1 FROM numbered_t curr 90 2 LEFT JOIN numbered_t prev ON (curr.rn = prev.rn+1)

94 OVER (SQL:2011) The Problem Direct access of other rows of the same window is not possible. (E.g., calculate the difference to the previous rows) WITH numbered_t AS (SELECT *, ROW_NUMBER() OVER(ORDER BY x) rn FROM t) SELECT curr.*, curr.balance - COALESCE(prev.balance,0) curr balance rn 50 1 FROM numbered_t curr 90 2 LEFT JOIN numbered_t prev ON (curr.rn = prev.rn+1)

95 OVER (SQL:2011) The Problem Direct access of other rows of the same window is not possible. (E.g., calculate the difference to the previous rows) WITH numbered_t AS (SELECT *, ROW_NUMBER() OVER(ORDER BY x) rn FROM t) SELECT curr.*, curr.balance - COALESCE(prev.balance,0) curr balance rn 50 1 FROM numbered_t curr 90 2 LEFT JOIN numbered_t prev ON (curr.rn = prev.rn+1)

96 OVER (SQL:2011) The Problem Direct access of other rows of the same window is not possible. (E.g., calculate the difference to the previous rows) WITH numbered_t AS (SELECT *, ROW_NUMBER() OVER(ORDER BY x) rn FROM t) SELECT curr.*, curr.balance - COALESCE(prev.balance,0) curr balance rn 50 1 prev balance rn 50 1 FROM numbered_t curr LEFT JOIN numbered_t prev ON (curr.rn = prev.rn+1)

97 OVER (SQL:2011) The Problem Direct access of other rows of the same window is not possible. (E.g., calculate the difference to the previous rows) WITH numbered_t AS (SELECT *, ROW_NUMBER() OVER(ORDER BY x) rn FROM t) SELECT curr.*, curr.balance - COALESCE(prev.balance,0) curr balance rn 50 1 prev balance rn FROM numbered_t curr LEFT JOIN numbered_t prev ON (curr.rn = prev.rn+1)

98 OVER (SQL:2011) The Problem Direct access of other rows of the same window is not possible. (E.g., calculate the difference to the previous rows) WITH numbered_t AS (SELECT *, ROW_NUMBER() OVER(ORDER BY x) rn FROM t) SELECT curr.*, curr.balance curr balance rn prev balance rn - COALESCE(prev.balance,0) FROM numbered_t curr LEFT JOIN numbered_t prev ON (curr.rn = prev.rn+1)

99 OVER (SQL:2011) Since SQL:2011 SQL:2011 introduced LEAD, LAG, NTH_VALUE, for that: SELECT *, balance - COALESCE( LAG(balance) OVER(ORDER BY x), 0) FROM t Available functions: LEAD / LAG FIRST_VALUE / LAST_VALUE NTH_VALUE(col, n) FROM FIRST/LAST RESPECT/IGNORE NULLS

100 OVER (LEAD, LAG, ) Since SQL: [0] MariaDB 8.0 [0] MySQL 8.4 [0] PostgreSQL SQLite 9.5 [1] 11.1 DB2 LUW 8i [1] 11gR2 Oracle [0] No IGNORE NULLS and FROM LAST [1] No NTH_VALUE 2012 [1] SQL Server

101 System Versioning (Time Traveling)

102 System Versioning The Problem INSERT UPDATE DELETE are DESTRUCTIVE

103 System Versioning Since SQL:2011 Table can be system versioned, application versioned or both. CREATE TABLE t (..., start_ts TIMESTAMP(9) GENERATED ALWAYS AS ROW START, end_ts TIMESTAMP(9) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (start_ts, end_ts) ) WITH SYSTEM VERSIONING

104 System Versioning Since SQL:2011 INSERT... (ID, DATA) VALUES (1, 'X') ID Data start_ts end_ts 1 X 10:00:00 UPDATE... SET DATA = 'Y'... ID Data start_ts end_ts 1 X 10:00:00 11:00:00 1 Y 11:00:00 DELETE... WHERE ID = 1

105 System Versioning ID Data start_ts end_ts 1 X 10:00:00 Since SQL:2011 UPDATE... SET DATA = 'Y'... ID Data start_ts end_ts 1 X 10:00:00 11:00:00 1 Y 11:00:00 DELETE... WHERE ID = 1 ID Data start_ts end_ts 1 X 10:00:00 11:00:00 1 Y 11:00:00 12:00:00

106 System Versioning Since SQL:2011 ID Data start_ts end_ts 1 X 10:00:00 11:00:00 1 Y 11:00:00 12:00:00 Although multiple versions exist, only the current one is visible per default. After 12:00:00, SELECT * FROM t doesn t return anything anymore.

107 System Versioning Since SQL:2011 ID Data start_ts end_ts 1 X 10:00:00 11:00:00 1 Y 11:00:00 12:00:00 With FOR AS OF you can query anything you like: SELECT * FROM t FOR SYSTEM_TIME AS OF TIMESTAMP ' :30:00' ID Data start_ts end_ts 1 X 10:00:00 11:00:00

108 System Versioning Since SQL: MariaDB [0] MySQL PostgreSQL SQLite 10.1 [1] DB2 LUW 10gR1 [2] Oracle 2016 SQL Server [0] Available in MariaDB 10.3 beta. [1] Third column required (tx id), history table required. [2] Functionality available using Flashback

109 SQL:2016 (released: )

110 LISTAGG

111 LISTAGG Since SQL:2016 grp val SELECT grp 1 B, LISTAGG(val, ', ') grp val 1 A WITHIN GROUP (ORDER BY val) 1 A, B, C 1 C FROM t 2 X GROUP BY grp 2 X Default LISTAGG(val, ', ' ON OVERFLOW ERROR) Default LISTAGG(val, ', ' ON OVERFLOW TRUNCATE '...' WITHOUT COUNT) 'A, B,...' LISTAGG(val, ', ' ON OVERFLOW TRUNCATE '...' WITH COUNT) 'A, B,...(1)'

112 LISTAGG Availability [0] MariaDB 4.1 [0] MySQL 7.4 [1] 8.4 [2] 9.0 [3] PostgreSQL [4] SQLite 10.5 [5] DB2 LUW 11gR1 12cR2 Oracle SQL Server [6] [0] group_concat [1] array_to_string [0] group_concat [1] array_to_string [2] [2] array_agg array_agg [3] string_agg [3] [4] group_concat w/o ORDER BY [5] No ON OVERFLOW clause [6] string_agg announced for vnext

113 New in SQL:2016 JSON LISTAGG ROW PATTERN MATCHING DATE FORMAT POLYMORPHIC TABLE FUNCTIONS

114 Modern SQL has evolved beyond the relational idea.

115 Modern SQL has evolved beyond the relational idea. If you are using SQL like 25 years ago, you are doing it wrong!

116 Modern SQL has evolved beyond the relational idea. If you are using SQL like 25 years ago, you are doing it wrong! A lot has happened since SQL-92.

117

118 I have shown you a few features today

119 I have shown you a few features today There are hundreds more to discover

120 @ModernSQL modern-sql.com My other website: Training & co:

Still using. Windows 3.1? So why stick to -

Still using. Windows 3.1? So why stick to - Still using Windows 3.1? So why stick to SQL-92? @ModernSQL - http://modern-sql.com/ @MarkusWinand SQL:1999 LATERAL LATERAL Before SQL:1999 Derived tables (from clause subqueries) cannot see outside: SELECT

More information

The Mother of All Query Languages: SQL in Modern Times

The Mother of All Query Languages: SQL in Modern Times The Mother of All Query Languages: SQL in Modern Times @MarkusWinand @ModernSQL http://www.almaden.ibm.com/cs/people/chamberlin/sequel-1974.pdf 1974 1992 SQL-92 Tied to the Relational Idea Relational Data

More information

Postgres Window Magic

Postgres Window Magic Postgres Window Magic BRUCE MOMJIAN This presentation explains the many window function facilities and how they can be used to produce useful SQL query results. Creative Commons Attribution License http://momjian.us/presentations

More information

SQL Data Query Language

SQL Data Query Language SQL Data Query Language André Restivo 1 / 68 Index Introduction Selecting Data Choosing Columns Filtering Rows Set Operators Joining Tables Aggregating Data Sorting Rows Limiting Data Text Operators Nested

More information

Copyright 2017, Oracle and/or its aff iliates. All rights reserved.

Copyright 2017, Oracle and/or its aff iliates. All rights reserved. Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment

More information

Still using. Windows 3.1? So why stick to SQL-92? Modern SQL in

Still using. Windows 3.1? So why stick to SQL-92? Modern SQL in Still using Windows 3.1? So why stick to SQL-92? Modern SQL in PostgreSQL @MarkusWinand SQL:1999 !"#$%"! LATERAL Before SQL:1999 Inline views can't refer to outside the view:!"#"$%&' &&()*+&,- &&.*/0&1!"#"$%&'

More information

20461: Querying Microsoft SQL Server 2014 Databases

20461: Querying Microsoft SQL Server 2014 Databases Course Outline 20461: Querying Microsoft SQL Server 2014 Databases Module 1: Introduction to Microsoft SQL Server 2014 This module introduces the SQL Server platform and major tools. It discusses editions,

More information

DB2 SQL Class Outline

DB2 SQL Class Outline DB2 SQL Class Outline The Basics of SQL Introduction Finding Your Current Schema Setting Your Default SCHEMA SELECT * (All Columns) in a Table SELECT Specific Columns in a Table Commas in the Front or

More information

SQL Server Windowing Functions

SQL Server Windowing Functions SQL Server Windowing Functions Enrique Catalá Bañuls Mentor, SolidQ MAP 2012 Microsoft Technical Ranger Microsoft Certified Trainer ecatala@solidq.com Twitter: @enriquecatala Enrique Catalá Bañuls Computer

More information

Sql Server Syllabus. Overview

Sql Server Syllabus. Overview Sql Server Syllabus Overview This SQL Server training teaches developers all the Transact-SQL skills they need to create database objects like Tables, Views, Stored procedures & Functions and triggers

More information

MySQL 8.0 Common Table Expressions & Windowing Functions

MySQL 8.0 Common Table Expressions & Windowing Functions 1 / 66 2 / 66 MySQL 8.0 Common Table Expressions & Windowing Functions Dave Stokes - MySQL Community Manager - Oracle 3 / 66 Safe Harbor Statement The following is intended to outline our general product

More information

Optional SQL Feature Summary

Optional SQL Feature Summary Optional SQL Feature Summary The following table lists all optional features included in the SQL standard, from SQL- 2003 to SQL-2016. It also indicates which features that are currently supported by Mimer

More information

COURSE OUTLINE MOC 20461: QUERYING MICROSOFT SQL SERVER 2014

COURSE OUTLINE MOC 20461: QUERYING MICROSOFT SQL SERVER 2014 COURSE OUTLINE MOC 20461: QUERYING MICROSOFT SQL SERVER 2014 MODULE 1: INTRODUCTION TO MICROSOFT SQL SERVER 2014 This module introduces the SQL Server platform and major tools. It discusses editions, versions,

More information

AVANTUS TRAINING PTE LTD

AVANTUS TRAINING PTE LTD [MS20461]: Querying Microsoft SQL Server 2014 Length : 5 Days Audience(s) : IT Professionals Level : 300 Technology : SQL Server Delivery Method : Instructor-led (Classroom) Course Overview This 5-day

More information

MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9)

MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9) Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 6 Professional Program: Data Administration and Management MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9) AGENDA

More information

After completing this course, participants will be able to:

After completing this course, participants will be able to: Querying SQL Server T h i s f i v e - d a y i n s t r u c t o r - l e d c o u r s e p r o v i d e s p a r t i c i p a n t s w i t h t h e t e c h n i c a l s k i l l s r e q u i r e d t o w r i t e b a

More information

What s New in MariaDB Server Max Mether VP Server

What s New in MariaDB Server Max Mether VP Server What s New in MariaDB Server 10.3 Max Mether VP Server Recap MariaDB 10.2 New in MariaDB 10.2 - GA since May 2017 What s New in 10.2 Analytics SQL Window Functions Common Table Expressions (CTE) JSON JSON

More information

Querying Microsoft SQL Server

Querying Microsoft SQL Server Querying Microsoft SQL Server Course 20461D 5 Days Instructor-led, Hands-on Course Description This 5-day instructor led course is designed for customers who are interested in learning SQL Server 2012,

More information

Querying Microsoft SQL Server

Querying Microsoft SQL Server Querying Microsoft SQL Server 20461D; 5 days, Instructor-led Course Description This 5-day instructor led course provides students with the technical skills required to write basic Transact SQL queries

More information

Querying Microsoft SQL Server 2008/2012

Querying Microsoft SQL Server 2008/2012 Querying Microsoft SQL Server 2008/2012 Course 10774A 5 Days Instructor-led, Hands-on Introduction This 5-day instructor led course provides students with the technical skills required to write basic Transact-SQL

More information

COURSE OUTLINE: Querying Microsoft SQL Server

COURSE OUTLINE: Querying Microsoft SQL Server Course Name 20461 Querying Microsoft SQL Server Course Duration 5 Days Course Structure Instructor-Led (Classroom) Course Overview This 5-day instructor led course provides students with the technical

More information

Greenplum SQL Class Outline

Greenplum SQL Class Outline Greenplum SQL Class Outline The Basics of Greenplum SQL Introduction SELECT * (All Columns) in a Table Fully Qualifying a Database, Schema and Table SELECT Specific Columns in a Table Commas in the Front

More information

20461: Querying Microsoft SQL Server

20461: Querying Microsoft SQL Server 20461: Querying Microsoft SQL Server Length: 5 days Audience: IT Professionals Level: 300 OVERVIEW This 5 day instructor led course provides students with the technical skills required to write basic Transact

More information

Querying Microsoft SQL Server (MOC 20461C)

Querying Microsoft SQL Server (MOC 20461C) Querying Microsoft SQL Server 2012-2014 (MOC 20461C) Course 21461 40 Hours This 5-day instructor led course provides students with the technical skills required to write basic Transact-SQL queries for

More information

QUERYING MICROSOFT SQL SERVER COURSE OUTLINE. Course: 20461C; Duration: 5 Days; Instructor-led

QUERYING MICROSOFT SQL SERVER COURSE OUTLINE. Course: 20461C; Duration: 5 Days; Instructor-led CENTER OF KNOWLEDGE, PATH TO SUCCESS Website: QUERYING MICROSOFT SQL SERVER Course: 20461C; Duration: 5 Days; Instructor-led WHAT YOU WILL LEARN This 5-day instructor led course provides students with

More information

Querying Microsoft SQL Server 2012/2014

Querying Microsoft SQL Server 2012/2014 Page 1 of 14 Overview This 5-day instructor led course provides students with the technical skills required to write basic Transact-SQL queries for Microsoft SQL Server 2014. This course is the foundation

More information

Oracle Database 11g: SQL and PL/SQL Fundamentals

Oracle Database 11g: SQL and PL/SQL Fundamentals Oracle University Contact Us: +33 (0) 1 57 60 20 81 Oracle Database 11g: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn In this course, students learn the fundamentals of SQL and PL/SQL

More information

FUN WITH ANALYTIC FUNCTIONS UTOUG TRAINING DAYS 2017

FUN WITH ANALYTIC FUNCTIONS UTOUG TRAINING DAYS 2017 FUN WITH ANALYTIC FUNCTIONS UTOUG TRAINING DAYS 2017 ABOUT ME Born and raised here in UT In IT for 10 years, DBA for the last 6 Databases and Data are my hobbies, I m rather quite boring This isn t why

More information

Course 20461C: Querying Microsoft SQL Server

Course 20461C: Querying Microsoft SQL Server Course 20461C: Querying Microsoft SQL Server Audience Profile About this Course This course is the foundation for all SQL Serverrelated disciplines; namely, Database Administration, Database Development

More information

20461D: Querying Microsoft SQL Server

20461D: Querying Microsoft SQL Server 20461D: Querying Microsoft SQL Server Course Details Course Code: Duration: Notes: 20461D 5 days This course syllabus should be used to determine whether the course is appropriate for the students, based

More information

Meet MariaDB Vicențiu Ciorbaru Software MariaDB Foundation * * 2017 MariaDB Foundation

Meet MariaDB Vicențiu Ciorbaru Software MariaDB Foundation * * 2017 MariaDB Foundation Meet MariaDB 10.3 Vicențiu Ciorbaru Software Engineer @ MariaDB Foundation vicentiu@mariadb.org * * What is MariaDB? MariaDB 5.1 (Feb 2010) - Making builds free MariaDB 5.2 (Nov 2010) - Community features

More information

Calculate the Running Total(Everything)

Calculate the Running Total(Everything) Calculate the Running Total(Everything Objective: List the running total of the annual salaries. SELECT EmployeeName,AnnualSalary,SUM(AnnualSalary OVER(ORDER BY EmployeeName AS Running_Total Employee --Checking

More information

MySQL 8.0 What s New in the Optimizer

MySQL 8.0 What s New in the Optimizer MySQL 8.0 What s New in the Optimizer Manyi Lu Director MySQL Optimizer & GIS Team, Oracle October 2016 Copyright Copyright 2 015, 2016,Oracle Oracle and/or and/or its its affiliates. affiliates. All All

More information

"Charting the Course to Your Success!" MOC D Querying Microsoft SQL Server Course Summary

Charting the Course to Your Success! MOC D Querying Microsoft SQL Server Course Summary Course Summary Description This 5-day instructor led course provides students with the technical skills required to write basic Transact-SQL queries for Microsoft SQL Server 2014. This course is the foundation

More information

Querying Microsoft SQL Server

Querying Microsoft SQL Server 20461 - Querying Microsoft SQL Server Duration: 5 Days Course Price: $2,975 Software Assurance Eligible Course Description About this course This 5-day instructor led course provides students with the

More information

Oracle Database: SQL and PL/SQL Fundamentals NEW

Oracle Database: SQL and PL/SQL Fundamentals NEW Oracle Database: SQL and PL/SQL Fundamentals NEW Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals training delivers the fundamentals of SQL and PL/SQL along with the

More information

Aster Data SQL and MapReduce Class Outline

Aster Data SQL and MapReduce Class Outline Aster Data SQL and MapReduce Class Outline CoffingDW education has been customized for every customer for the past 20 years. Our classes can be taught either on site or remotely via the internet. Education

More information

Oracle Database: SQL and PL/SQL Fundamentals Ed 2

Oracle Database: SQL and PL/SQL Fundamentals Ed 2 Oracle University Contact Us: Local: 1800 103 4775 Intl: +91 80 67863102 Oracle Database: SQL and PL/SQL Fundamentals Ed 2 Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals

More information

Querying Microsoft SQL Server

Querying Microsoft SQL Server Querying Microsoft SQL Server Duration: 5 Days (08:30-16:00) Overview: This course provides students with the technical skills required to write basic Transact-SQL queries for Microsoft SQL Server. This

More information

Aster Data Basics Class Outline

Aster Data Basics Class Outline Aster Data Basics Class Outline CoffingDW education has been customized for every customer for the past 20 years. Our classes can be taught either on site or remotely via the internet. Education Contact:

More information

Chapter 6 Windowed Tables and Window Functions in SQL

Chapter 6 Windowed Tables and Window Functions in SQL Prof. Dr.-Ing. Stefan Deßloch AG Heterogene Informationssysteme Geb. 36, Raum 329 Tel. 0631/205 3275 dessloch@informatik.uni-kl.de Chapter 6 Windowed Tables and Window Functions in SQL Recent Developments

More information

Querying Microsoft SQL Server

Querying Microsoft SQL Server Course Code: M20461 Vendor: Microsoft Course Overview Duration: 5 RRP: POA Querying Microsoft SQL Server Overview This 5-day instructor led course provides delegates with the technical skills required

More information

Chapter 6 Windowed Tables and Window Functions in SQL

Chapter 6 Windowed Tables and Window Functions in SQL Prof. Dr.-Ing. Stefan Deßloch AG Heterogene Informationssysteme Geb. 36, Raum 329 Tel. 0631/205 3275 dessloch@informatik.uni-kl.de Chapter 6 Windowed Tables and Window Functions in SQL Outline Overview

More information

Chapter 9 Windowed Tables and Window Functions in SQL. Recent Development for Data Models 2016 Stefan Deßloch

Chapter 9 Windowed Tables and Window Functions in SQL. Recent Development for Data Models 2016 Stefan Deßloch Chapter 9 Windowed Tables and Window Functions in SQL Recent Development for Data Models 2016 Stefan Deßloch Windowed Table Functions Windowed table function operates on a window of a table returns a value

More information

Nested Queries. Dr Paolo Guagliardo. Aggregate results in WHERE The right way. Fall 2018

Nested Queries. Dr Paolo Guagliardo. Aggregate results in WHERE The right way. Fall 2018 Nested Queries Dr Paolo Guagliardo dbs-lecturer@ed.ac.uk Fall 2018 Aggregate results in WHERE The right way Account Number Branch CustID Balance 111 London 1 1330.00 222 London 2 1756.00 333 Edinburgh

More information

Microsoft Querying Microsoft SQL Server 2014

Microsoft Querying Microsoft SQL Server 2014 1800 ULEARN (853 276) www.ddls.com.au Microsoft 20461 - Querying Microsoft SQL Server 2014 Length 5 days Price $4290.00 (inc GST) Version D Overview Please note: Microsoft have released a new course which

More information

Andrea Martorana Tusa. T-SQL Advanced: Grouping and Windowing

Andrea Martorana Tusa. T-SQL Advanced: Grouping and Windowing Andrea Martorana Tusa T-SQL Advanced: Grouping and Windowing Sponsor Organizzatori GetLatestVersion. it Speaker info First name: Andrea. Last name: Martorana Tusa. Italian, working by Widex a danish company

More information

Lists and Recursion and Trees

Lists and Recursion and Trees Lists and Recursion and Trees Oh My! FOSDEM, Brussels, February 7, 2010 Copyright 2010 David Fetter david.fetter@pgexperts.com All Rights Reserved Better, Faster TPS Reports New! Reach Outside the Current

More information

Querying Microsoft SQL Server 2014

Querying Microsoft SQL Server 2014 Querying Microsoft SQL Server 2014 Código del curso: 20461 Duración: 5 días Acerca de este curso This 5 day instructor led course provides students with the technical skills required to write basic Transact

More information

Chapter 11 Object and Object- Relational Databases

Chapter 11 Object and Object- Relational Databases Chapter 11 Object and Object- Relational Databases Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 11 Outline Overview of Object Database Concepts Object-Relational

More information

5. Single-row function

5. Single-row function 1. 2. Introduction Oracle 11g Oracle 11g Application Server Oracle database Relational and Object Relational Database Management system Oracle internet platform System Development Life cycle 3. Writing

More information

Chapter 6 Windowed Tables and Window Functions in SQL

Chapter 6 Windowed Tables and Window Functions in SQL Prof. Dr.Ing. Stefan Deßloch AG Heterogene Informationssysteme Geb., Raum Tel. 0/0 dessloch@informatik.unikl.de Chapter Windowed Tables and Window Functions in SQL WS0/0 Outline Overview I. ObjectRelational

More information

Standard SQL Reserved Words Summary

Standard SQL Reserved Words Summary Standard SQL Reserved Words Summary The following table lists all reserved words in the SQL standard, from SQL-92 to SQL- 2016. Note! Mimer SQL does not add any additional reserved words. In fact, Mimer

More information

SQL Saturday Cork Welcome to Cork. Andrea Martorana Tusa T-SQL advanced: Grouping and Windowing

SQL Saturday Cork Welcome to Cork. Andrea Martorana Tusa T-SQL advanced: Grouping and Windowing SQL Saturday Cork Welcome to Cork Andrea Martorana Tusa T-SQL advanced: Grouping and Windowing Andrea Martorana Tusa T-SQL Advanced: Grouping and Windowing Speaker info First name: Andrea. Last name: Martorana

More information

Database Management Systems,

Database Management Systems, Database Management Systems SQL Query Language (3) 1 Topics Aggregate Functions in Queries count sum max min avg Group by queries Set Operations in SQL Queries Views 2 Aggregate Functions Tables are collections

More information

Oracle Syllabus Course code-r10605 SQL

Oracle Syllabus Course code-r10605 SQL Oracle Syllabus Course code-r10605 SQL Writing Basic SQL SELECT Statements Basic SELECT Statement Selecting All Columns Selecting Specific Columns Writing SQL Statements Column Heading Defaults Arithmetic

More information

ORACLE TRAINING CURRICULUM. Relational Databases and Relational Database Management Systems

ORACLE TRAINING CURRICULUM. Relational Databases and Relational Database Management Systems ORACLE TRAINING CURRICULUM Relational Database Fundamentals Overview of Relational Database Concepts Relational Databases and Relational Database Management Systems Normalization Oracle Introduction to

More information

Querying Data with Transact SQL

Querying Data with Transact SQL Course 20761A: Querying Data with Transact SQL Course details Course Outline Module 1: Introduction to Microsoft SQL Server 2016 This module introduces SQL Server, the versions of SQL Server, including

More information

20761 Querying Data with Transact SQL

20761 Querying Data with Transact SQL Course Overview The main purpose of this course is to give students a good understanding of the Transact-SQL language which is used by all SQL Server-related disciplines; namely, Database Administration,

More information

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe Chapter 12 Outline Overview of Object Database Concepts Object-Relational Features Object Database Extensions to SQL ODMG Object Model and the Object Definition Language ODL Object Database Conceptual

More information

Relational Database Management Systems for Epidemiologists: SQL Part II

Relational Database Management Systems for Epidemiologists: SQL Part II Relational Database Management Systems for Epidemiologists: SQL Part II Outline Summarizing and Grouping Data Retrieving Data from Multiple Tables using JOINS Summary of Aggregate Functions Function MIN

More information

In This Lecture. Yet More SQL SELECT ORDER BY. SQL SELECT Overview. ORDER BY Example. ORDER BY Example. Yet more SQL

In This Lecture. Yet More SQL SELECT ORDER BY. SQL SELECT Overview. ORDER BY Example. ORDER BY Example. Yet more SQL In This Lecture Yet More SQL Database Systems Lecture 9 Natasha Alechina Yet more SQL ORDER BY Aggregate functions and HAVING etc. For more information Connoly and Begg Chapter 5 Ullman and Widom Chapter

More information

2000 Lines of Java? Or 50 Lines of SQL? The Choice is Yours

2000 Lines of Java? Or 50 Lines of SQL? The Choice is Yours 2000 Lines of Java? Or 50 Lines of SQL? The Choice is Yours Me @lukaseder - Founder and CEO at Data Geekery - SQL Aficionado - Java Aficionado SQL is a device whose mystery is only exceeded by its power!

More information

SQL, the underestimated Big Data technology

SQL, the underestimated Big Data technology SQL, the underestimated Big Data technology No tation Seen at the 2013 O Reilly Strata Conf: History of NoSQL by Mark Madsen. Picture published by Edd Dumbill NoSQL? NoSQL? No, SQL! Our vision at Data

More information

ASSIGNMENT NO Computer System with Open Source Operating System. 2. Mysql

ASSIGNMENT NO Computer System with Open Source Operating System. 2. Mysql ASSIGNMENT NO. 3 Title: Design at least 10 SQL queries for suitable database application using SQL DML statements: Insert, Select, Update, Delete with operators, functions, and set operator. Requirements:

More information

Advanced SQL. 04 Window Functions. Torsten Grust Universität Tübingen, Germany

Advanced SQL. 04 Window Functions. Torsten Grust Universität Tübingen, Germany Advanced SQL 04 Window Functions Torsten Grust Universität Tübingen, Germany 1 Window Functions With SQL:2003, the ISO SQL Standard introduced window functions, a new mode of row-based computation: SQL

More information

Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Administrivia. Administrivia. Faloutsos/Pavlo CMU /615

Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Administrivia. Administrivia. Faloutsos/Pavlo CMU /615 Carnegie Mellon Univ. Dept. of Computer Science 15-415/615 - DB Applications C. Faloutsos A. Pavlo Lecture#14(b): Implementation of Relational Operations Administrivia HW4 is due today. HW5 is out. Faloutsos/Pavlo

More information

Oracle Database 10g: Introduction to SQL

Oracle Database 10g: Introduction to SQL ORACLE UNIVERSITY CONTACT US: 00 9714 390 9000 Oracle Database 10g: Introduction to SQL Duration: 5 Days What you will learn This course offers students an introduction to Oracle Database 10g database

More information

NULLs & Outer Joins. Objectives of the Lecture :

NULLs & Outer Joins. Objectives of the Lecture : Slide 1 NULLs & Outer Joins Objectives of the Lecture : To consider the use of NULLs in SQL. To consider Outer Join Operations, and their implementation in SQL. Slide 2 Missing Values : Possible Strategies

More information

1 Writing Basic SQL SELECT Statements 2 Restricting and Sorting Data

1 Writing Basic SQL SELECT Statements 2 Restricting and Sorting Data 1 Writing Basic SQL SELECT Statements Objectives 1-2 Capabilities of SQL SELECT Statements 1-3 Basic SELECT Statement 1-4 Selecting All Columns 1-5 Selecting Specific Columns 1-6 Writing SQL Statements

More information

More SQL in MySQL 8.0

More SQL in MySQL 8.0 More SQL in MySQL 8.0 Norvald H. Ryeng Sofware Development Senior Manager MySQL Optmizer Team November, 08 Program Agenda 3 4 Common table expressions (CTEs) Window functons JSON_TABLE Demo 5 6 7 3 Theory

More information

PASSWORDS TREES AND HIERARCHIES. CS121: Relational Databases Fall 2017 Lecture 24

PASSWORDS TREES AND HIERARCHIES. CS121: Relational Databases Fall 2017 Lecture 24 PASSWORDS TREES AND HIERARCHIES CS121: Relational Databases Fall 2017 Lecture 24 Account Password Management 2 Mentioned a retailer with an online website Need a database to store user account details

More information

SQL Server 2012 Development Course

SQL Server 2012 Development Course SQL Server 2012 Development Course Exam: 1 Lecturer: Amirreza Keshavarz May 2015 1- You are a database developer and you have many years experience in database development. Now you are employed in a company

More information

Exact Numeric Data Types

Exact Numeric Data Types SQL Server Notes for FYP SQL data type is an attribute that specifies type of data of any object. Each column, variable and expression has related data type in SQL. You would use these data types while

More information

Oracle Compare Two Database Tables Sql Query List All

Oracle Compare Two Database Tables Sql Query List All Oracle Compare Two Database Tables Sql Query List All We won't show you that ad again. I need to implement comparing 2 tables by set of keys (columns of compared tables). This pl/sql stored procedure works

More information

SQL. The Basics Advanced Manipulation Constraints Authorization 1. 1

SQL. The Basics Advanced Manipulation Constraints Authorization 1. 1 SQL The Basics Advanced Manipulation Constraints Authorization 1. 1 Table of Contents SQL 0 Table of Contents 0/1 Parke Godfrey 0/2 Acknowledgments 0/3 SQL: a standard language for accessing databases

More information

Querying Microsoft SQL Server 2014

Querying Microsoft SQL Server 2014 Querying Microsoft SQL Server 2014 Referencia MOC 20461 Duración (horas) 25 Última actualización 27 marzo 2018 Modalidades Presencial, a medida Examen 70-461 Introducción This 5-day instructor led course

More information

Why Relational Databases? Relational databases allow for the storage and analysis of large amounts of data.

Why Relational Databases? Relational databases allow for the storage and analysis of large amounts of data. DATA 301 Introduction to Data Analytics Relational Databases Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca DATA 301: Data Analytics (2) Why Relational Databases? Relational

More information

Database Lab Queries. Fall Term 2017 Dr. Andreas Geppert

Database Lab Queries. Fall Term 2017 Dr. Andreas Geppert Database Lab Queries Fall Term 2017 Dr. Andreas Geppert geppert@acm.org Topics conceptual design logical design consistency constraints data manipulation queries transactions views stored procedures and

More information

Advanced SQL Tribal Data Workshop Joe Nowinski

Advanced SQL Tribal Data Workshop Joe Nowinski Advanced SQL 2018 Tribal Data Workshop Joe Nowinski The Plan Live demo 1:00 PM 3:30 PM Follow along on GoToMeeting Optional practice session 3:45 PM 5:00 PM Laptops available What is SQL? Structured Query

More information

Trees & Hierarchies in SQL. Joe Celko Copyright 2009

Trees & Hierarchies in SQL. Joe Celko Copyright 2009 Trees & Hierarchies in SQL Joe Celko Copyright 2009 Trees in SQL Trees are graph structures used to represent Hierarchies Parts explosions Organizational charts Three major methods in SQL Adjacency list

More information

Rows and Range, Preceding and Following

Rows and Range, Preceding and Following Rows and Range, Preceding and Following SQL Server 2012 adds many new features to Transact SQL (T-SQL). One of my favorites is the Rows/Range enhancements to the over clause. These enhancements are often

More information

Application-enabling features of DB2 for z/os. June Charles Lewis DB2 for z/os Advisor IBM Mid-Atlantic Business Unit

Application-enabling features of DB2 for z/os. June Charles Lewis DB2 for z/os Advisor IBM Mid-Atlantic Business Unit Application-enabling features of DB2 for z/os June 2016 Charles Lewis DB2 for z/os Advisor IBM Mid-Atlantic Business Unit lewisc@us.ibm.com The aim of this presentation To help ensure that you are aware

More information

What s New in MariaDB Server 10.3

What s New in MariaDB Server 10.3 What s New in MariaDB Server 10.3 What s New in MariaDB Server 10.3 Database Compatibility Enhancements PL/SQL Compatibility for MariaDB Stored Functions including packages PL/SQL Compatibility for MariaDB

More information

$99.95 per user. Writing Queries for SQL Server (2005/2008 Edition) CourseId: 160 Skill level: Run Time: 42+ hours (209 videos)

$99.95 per user. Writing Queries for SQL Server (2005/2008 Edition) CourseId: 160 Skill level: Run Time: 42+ hours (209 videos) Course Description This course is a comprehensive query writing course for Microsoft SQL Server versions 2005, 2008, and 2008 R2. If you struggle with knowing the difference between an INNER and an OUTER

More information

Part XII. Mapping XML to Databases. Torsten Grust (WSI) Database-Supported XML Processors Winter 2008/09 321

Part XII. Mapping XML to Databases. Torsten Grust (WSI) Database-Supported XML Processors Winter 2008/09 321 Part XII Mapping XML to Databases Torsten Grust (WSI) Database-Supported XML Processors Winter 2008/09 321 Outline of this part 1 Mapping XML to Databases Introduction 2 Relational Tree Encoding Dead Ends

More information

INDEX. 1 Basic SQL Statements. 2 Restricting and Sorting Data. 3 Single Row Functions. 4 Displaying data from multiple tables

INDEX. 1 Basic SQL Statements. 2 Restricting and Sorting Data. 3 Single Row Functions. 4 Displaying data from multiple tables INDEX Exercise No Title 1 Basic SQL Statements 2 Restricting and Sorting Data 3 Single Row Functions 4 Displaying data from multiple tables 5 Creating and Managing Tables 6 Including Constraints 7 Manipulating

More information

Querying Data with Transact-SQL

Querying Data with Transact-SQL Course 20761A: Querying Data with Transact-SQL Page 1 of 5 Querying Data with Transact-SQL Course 20761A: 2 days; Instructor-Led Introduction The main purpose of this 2 day instructor led course is to

More information

Introduction to Computer Science and Business

Introduction to Computer Science and Business Introduction to Computer Science and Business This is the second portion of the Database Design and Programming with SQL course. In this portion, students implement their database design by creating a

More information

What Are Group Functions? Reporting Aggregated Data Using the Group Functions. Objectives. Types of Group Functions

What Are Group Functions? Reporting Aggregated Data Using the Group Functions. Objectives. Types of Group Functions What Are Group Functions? Group functions operate on sets of rows to give one result per group. Reporting Aggregated Data Using the Group Functions Maximum salary in table Copyright 2004, Oracle. All rights

More information

Oracle Database: Introduction to SQL Ed 2

Oracle Database: Introduction to SQL Ed 2 Oracle University Contact Us: +40 21 3678820 Oracle Database: Introduction to SQL Ed 2 Duration: 5 Days What you will learn This Oracle Database 12c: Introduction to SQL training helps you write subqueries,

More information

Oral Questions and Answers (DBMS LAB) Questions & Answers- DBMS

Oral Questions and Answers (DBMS LAB) Questions & Answers- DBMS Questions & Answers- DBMS https://career.guru99.com/top-50-database-interview-questions/ 1) Define Database. A prearranged collection of figures known as data is called database. 2) What is DBMS? Database

More information

2000 Lines of Java? Or 50 Lines of SQL? The Choice is Yours

2000 Lines of Java? Or 50 Lines of SQL? The Choice is Yours 2000 Lines of Java? Or 50 Lines of SQL? The Choice is Yours Me @lukaseder - Founder and CEO at Data Geekery - SQL Aficionado - Java Aficionado SQL is a device whose mystery is only exceeded by its power!

More information

MIS NETWORK ADMINISTRATOR PROGRAM

MIS NETWORK ADMINISTRATOR PROGRAM NH107-7475 SQL: Querying and Administering SQL Server 2012-2014 136 Total Hours 97 Theory Hours 39 Lab Hours COURSE TITLE: SQL: Querying and Administering SQL Server 2012-2014 PREREQUISITE: Before attending

More information

Course 20461C: Querying Microsoft SQL Server

Course 20461C: Querying Microsoft SQL Server Course 20461C: Querying Microsoft SQL Server About this course: This course is the foundation for all SQL Server related disciplines; namely, Database Administration, Database development and business

More information

Writing Your First Common Table Expression with SQL Server

Writing Your First Common Table Expression with SQL Server Writing Your First Common Table Expression with SQL Server Day 2 of Common Table Expression Month (June) at SteveStedman.com, today I will cover creating your very first CTE. Keep in mind that this may

More information

Course Details Duration: 3 days Starting time: 9.00 am Finishing time: 4.30 pm Lunch and refreshments are provided.

Course Details Duration: 3 days Starting time: 9.00 am Finishing time: 4.30 pm Lunch and refreshments are provided. Database Administration with PostgreSQL Introduction This is a 3 day intensive course in skills and methods for PostgreSQL. Course Details Duration: 3 days Starting time: 9.00 am Finishing time: 4.30 pm

More information

Query Optimizer MySQL vs. PostgreSQL

Query Optimizer MySQL vs. PostgreSQL Percona Live, Santa Clara (USA), 24 April 2018 Christian Antognini @ChrisAntognini antognini.ch/blog BASEL BERN BRUGG DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. GENEVA HAMBURG COPENHAGEN LAUSANNE MUNICH

More information

CS 464/564 Introduction to Database Management System Instructor: Abdullah Mueen

CS 464/564 Introduction to Database Management System Instructor: Abdullah Mueen CS 464/564 Introduction to Database Management System Instructor: Abdullah Mueen LECTURE 10: INTRODUCTION TO SQL FULL RELATIONAL OPERATIONS MODIFICATION LANGUAGE Union, Intersection, Differences (select

More information

DATABASE MANAGEMENT SYSTEMS PREPARED BY: ENGR. MOBEEN NAZAR

DATABASE MANAGEMENT SYSTEMS PREPARED BY: ENGR. MOBEEN NAZAR DATABASE MANAGEMENT SYSTEMS PREPARED BY: ENGR. MOBEEN NAZAR SCHEME OF PRESENTATION LAB MARKS DISTRIBUTION LAB FILE DBMS PROJECT INSTALLATION STEPS FOR SQL SERVER 2008 SETTING UP SQL SERVER 2008 INTRODUCTION

More information