Boost your T-SQL with the APPLY Operator

Slides:



Advertisements
Similar presentations
Jeffrey Snover | Distinguished Engineer & Lead Architect Jason Helmick | Senior Technologist, Concentrated Technology.
Advertisements

Steven Borg | Co-founder & Strategist, Northwest Cadence Anthony Borton | ALM Consultant, Enhance ALM.
Jon Galloway | Technical Evangelist Christopher Harrison | Content Developer.
Steven Borg | Co-founder & Strategist, Northwest Cadence Anthony Borton | ALM Consultant, Enhance ALM.
Kate Gregory | Gregory Consulting James McNellis | Senior Engineer, Visual C++
Gerry O’Brien| Technical Content Development Manager Paul Pardi| Senior Content Publishing Manager.
Steven Borg | Co-founder & Strategist, Northwest Cadence Anthony Borton | ALM Consultant, Enhance ALM.
▪ Microsoft Virtual Academy—Free online training! ‒ Tailored for IT Pros and Developers ‒ Over 1M registered users ▪ Earn while you learn! ‒ 50 MVA Points.
Join the MVA Community! ▪ Microsoft Virtual Academy—Free online training! ‒ Tailored for IT Pros and Developers ‒ Over 1M registered users ▪ Earn while.
Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master.
Join the MVA Community! ▪ Microsoft Virtual Academy—Free online training! ‒ Tailored for IT Pros and Developers ‒ Over 1M registered users ▪ Earn while.
Jon Galloway | Development Platform Evangelist Christopher Harrison | Microsoft Certified Trainer.
04 | Grouping and Aggregating Data Brian Alderman | MCT, CEO / Founder of MicroTechPoint Tobias Ternstrom | Microsoft SQL Server Program Manager.
Microsoft Virtual Academy Stacey Mulcahy | Technical Evangelist Christopher Harrison | Content Developer.
Jeffrey Snover | Distinguished Engineer & Lead Architect Jason Helmick | Senior Technologist, Concentrated Technology.
Chapter 12 Subqueries and Merge Statements
Join the MVA Community! ▪ Microsoft Virtual Academy—Free online training! ‒ Tailored for IT Pros and Developers ‒ Over 1M registered users ▪ Earn while.
Join the MVA Community! ▪ Microsoft Virtual Academy—Free online training! ‒ Tailored for IT Pros and Developers ‒ Over 1M registered users ▪ Earn while.
Register for these FREE Jump Starts—NOW! January 30 | Virtualization for VMware Pros − Late Feb | Tools for VMware.
Naqash Ahmed | Microsoft Student Partner. Naqash Ahmed | Student of Bachelors in Software Engineering Microsoft Student Partner since November.
Join the MVA Community! ▪ Microsoft Virtual Academy—Free online training! ‒ Tailored for IT Pros and Developers ‒ Over 1M registered users ▪ Earn while.
Cross Platform Development with Xamarin & Visual Studio 2013
3D Printing Essentials Emmett Lalish | Mechanical Engineer
Introduction to Tabular Data Models
Porting your Unity Game to the Windows Store Jump Start
Chapter 12 Subqueries and MERGE Oracle 10g: SQL
Querying Multiple Tables
Web API Design Jeremy Likness | Principal Architect
20761A 10: Using Subqueries Module 10   Using Subqueries.
20761A 11: Using Set Operators Module 11   Using Set Operators.
Designing Database Solutions for SQL Server
Becoming a Visio 2013 Power User – Part 3
Programming Robotic Systems using Visual Studio
SQL Server Optimizing Query Plans
Learn more: Expand your Cloud Knowledge
Querying Multiple Tables
06 | Using Subqueries and APPLY
20761B 12: Using Set Operators Module 12   Using Set Operators.
Creating Windows Store Apps Using Visual Basic
Cross Platform Development with Xamarin & Visual Studio 2013
20761B 10: Using Subqueries Module 10   Using Subqueries.
Office 365 Admin Support Skills: Service Management
Join the MVA Community! Microsoft Virtual Academy—Free online training! Tailored for IT Pros and Developers Over 1M registered users Earn while you learn!
Introduction to AngularJS
Introduction to jQuery
Getting Started with PowerShell Desired State Configuration (DSC)
MAP & ACT Pre deployment planning for Windows 7 or Server 2008 R2
Join the MVA Community! Microsoft Virtual Academy—Free online training! Tailored for IT Pros and Developers Over 2M registered users Earn while you learn!
Reimagine Finance: Managing Controls and Compliance
Game Production Basics
Steven Borg | Co-Founder & Strategist, Northwest Cadence
Developing Microsoft Azure Solutions Jump Start
A Lap Around Azure Websites Introduction
DevOps - Visual Studio Release Management Jump Start
Single Page Applications with jQuery or AngularJS
Developing Universal Windows Apps with HTML and JavaScript
Quick Start Challenge: Universal Projects to Build a Game
Pranav Rastogi | Program Manager, Microsoft
Quick Start Challenge: Microsoft Advertising SDK
Trainer: Bach Ngoc Toan– TEDU Website:
Lighting Up Real-time Web Communications with SignalR Introduction
Azure SQL Database for Business Critical Cloud Applications
Stacey Mulcahy| Technical Evangelist Jamie Kosoy | Content Developer
Getting Started with PowerShell Jump Start
Jeffrey Snover | Distinguished Engineer & Lead Architect
05 | Testers’ Role in the DevOps World
What’s ASP.NET 5 and Why? Scott Hunter | Director of Program Management Scott Hanselman | Principal Program Manager.
Git Jump Start Steven Borg | Co-founder & Strategist, Northwest Cadence James Tupper| ALM Consultant, Northwest Cadence.
Getting Started with Microsoft Azure Machine Learning
Adding Style with CSS Helen Zeng | Developer Evangelist
Presentation transcript:

Boost your T-SQL with the APPLY Operator Itzik Ben-Gan | T-SQL Trainer and Co-founder, SolidQ Umachandar Jayachandran (UC) | Program Manager, Microsoft

Meet Itzik Ben-Gan | ‏@ItzikBenGan T-SQL Trainer and Co-founder, SolidQ Delivering T-SQL training around the world (http://tsql.solidq.com/courses.htm) Author of many T-SQL books Columnist, SQL Server Pro Magazine Regular speaker at events like SQL PASS and Dev Connections Over two decades of experience with SQL and databases

Meet Umachandar Jayachandran (UC) Program Manager, Microsoft SQL Server Product Group Worked on SQL Server since 2008 release Currently working on Windows Azure SQL Database Have worked with databases (Sybase, Oracle & SQL Server) since 1998 Microsoft representative for ANSI SQL standards group

Course Topics Boost your T-SQL with the APPLY Operator 01 | APPLY, Described 02 | APPLY Boosts various T-SQL Features

Setting Expectations Target Audience T-SQL practitioners with at least half a year of experience Suggested Prerequisites/Supporting Material Microsoft SQL Server 2012 T-SQL Fundamentals (MSPress, 2012) Source code: http://tsql.solidq.com/books/source_code/APPLY.txt Few leading slides – mostly T-SQL coding demos!

Join the MVA Community! Microsoft Virtual Academy Free online learning tailored for IT Pros and Developers Over 1M registered users Up-to-date, relevant training on variety of Microsoft products

01 | APPLY, Described Itzik Ben-Gan | T-SQL Trainer and Co-founder, SolidQ Umachandar Jayachandran (UC) | Program Manager, Microsoft

Module Overview Joins vs. APPLY CROSS APPLY OUTER APPLY Implicit APPLY

Joins vs. APPLY Cross Join Inner Join APPLY (2005+) Both input sets predefined (pre-operator treatment), Result: all combinations Inner Join Both input sets predefined, Result: only matching combinations APPLY (2005+) Left input set predefined, Right set evaluated per left row using correlations Result: unified results of evaluations X All Combinations X + ? Matching Combinations 1 2 Unified Results

CROSS APPLY Apply right set per left row using correlations Left rows discarded if right side is empty SELECT C.custid, C.companyname, O.orderid, O.orderdate, O.empid FROM Sales.Customers AS C CROSS APPLY dbo.GetTopOrders(C.custid, 3) AS O;

OUTER APPLY Apply right set per left row using correlations Left rows preserved when right side is empty NULLs used as placeholders SELECT C.custid, C.companyname, O.orderid, O.orderdate, O.empid FROM Sales.Customers AS C OUTER APPLY dbo.GetTopOrders(C.custid, 3) AS O;

Implicit APPLY Refer to a table UDF in subquery Pass columns from outer table as inputs (correlations) SELECT C.custid, C.companyname, (SELECT COUNT(DISTINCT empid) FROM dbo.GetTopOrders(C.custid, 3) AS O) AS numemps FROM Sales.Customers AS C;