70-461 Session 6: Querying Microsoft SQL Server (T-SQL)
4.5 (23 ratings)
Instead of using a simple lifetime average, Udemy calculates a course's star rating by considering a number of different factors such as the number of ratings, the age of ratings, and the likelihood of fraudulent ratings.
464 students enrolled
Wishlisted Wishlist

Please confirm that you want to add 70-461 Session 6: Querying Microsoft SQL Server (T-SQL) to your Wishlist.

Add to Wishlist

70-461 Session 6: Querying Microsoft SQL Server (T-SQL)

Using T-SQL, correlated subqueries, CTEs, Pivots, UDFs, uniqueidentifiers and Sequences. SQL 2012 to 2016 (inc. 70-761).
4.5 (23 ratings)
Instead of using a simple lifetime average, Udemy calculates a course's star rating by considering a number of different factors such as the number of ratings, the age of ratings, and the likelihood of fraudulent ratings.
464 students enrolled
Created by Phillip Burton
Last updated 5/2016
Current price: $12 Original price: $50 Discount: 76% off
3 days left at this price!
30-Day Money-Back Guarantee
  • 3.5 hours on-demand video
  • 1 Article
  • 1 Supplemental Resource
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of Completion

Training 5 or more people?

Get your team access to Udemy's top 2,000 courses anytime, anywhere.

Try Udemy for Business
What Will I Learn?
  • Learn all about subqueries, using them in the SELECT, FROM and WHERE clauses.
  • Learn about correlated subqueries, where the results of the subquery depends on the main query.
  • Learn about Common Table Expressions (CTE), using the WITH statement.
  • Use ROW_NUMBER, LAG and CTEs to group consecutive numbers.
  • Learn about PIVOT and UNPIVOT to spread data across columns.
  • Find out all about functions, including UDFs (user defined functions): scalar, inline table and multi-statement table functions
  • "Join" the functions into tables using the CROSS APPLY and OUTER APPLY.
  • Learn about synonyms, dynamic SQL and SQL injection.
  • Find out about uniqueidentifiers (NEWID and NEWSEQUENTIALID functions), and create and use Sequences.
View Curriculum
  • You need to know about data types and functions, SELECT queries, and ranking functions.
  • If you don't, then you should take my earlier Sessions first.
  • There is a 30-day money back guarantee of this Udemy course.
  • Why not have a look at the curriculum below and see what you can learn?

This course is the foundation for the Microsoft Certificate 70-461: "Querying Microsoft SQL Server 2012".

In Sessions 1 and 2, we learned all about dates, strings and number data types and DML statements. In sessions 3 and 4, we created views, procedures, triggers, constraints and combining datasets, and in session 5 we learned about ranking and aggregate functions.

We'll will now be creating sub-queries, working through objectives 7b-e of the exam 70-461. We'll be created correlated subqueries, where the results of the subquery depend on the main query. We'll be looking at Common Table Expressions using the WITH statement, and we'll be using what we have learned to solve a common business problem.

We'll be looking at functions (objective 14), including the three different types of User Defined Functions (UDF): scalar functions, inline table functions, and multi-statement table functions. We'll then complete objective 6 by looking at synonyms and dynamic SQL, and objective 8 by looking at the use of GUIDs. We'll also look at sequences.

No prior knowledge other than what we covered in Sessions 1 to 5 is required. This course builds on the knowledge previously gained in those previous sessions.

There are regular quizzes to help you remember the information.

Once finished, you will know what how to write subqueries, functions, sequences and more, and we'll have expanded on our current knowledge of T-SQL.

Who is the target audience?
  • This course is for you if want a refresher course in SQL, or are learning SQL for the first time.
  • This course is for you if you are working towards the requirements for exam 70-461, or if you just want to expand your knowledge of T-SQL.
  • If you are starting from the beginning, then you should look at my sessions 1 to 5 courses before taking this session 6.
  • If you want more advanced topics, then please look at my other sessions.
Compare to Other Microsoft SQL Courses
Curriculum For This Course
32 Lectures
3 Lectures 05:41

Welcome back. A quick recap of where we are.

Preview 02:57

We'll have a look at the structure of this session, and what we are going to learn.

Preview 02:33

Objective 7: Sub-queries
8 Lectures 01:00:39

A reminder of the tables that we created all the way back in Session 2.

Table structure

We'll have a look at using subqueries in the WHERE clause.

The WHERE clause

We'll have a look at using subqueries in the WHERE clause, and how much care you have to use with using the word NOT.


We'll expand our use of the WHERE clause by looking at ANY, SOME and ALL.


We'll be looking at the use of subqueries in the FROM clause.

Preview 10:58

We'll look at using subqueries in the SELECT clause, and see that we have to use correlated subqueries in the SELECT clause.

The SELECT clause

We'll revisit the WHERE clause, and use correlated subqueries in the WHERE clause.

Correlated subquery - WHERE

We'll look at objective 6a, and use a subquery to obtain the top 5 from various categories.

Top 5 from various categories
Objective 7e: WITH statement
3 Lectures 24:53

We'll introduce the WITH statement, and see how it can clarify our code.

WITH statement

We'll find out what Employee Numbers have not been used, and find out why we have to generate a list of numbers using WITH and ROW_NUMBER to do so.

Generating a list of numbers

We'll summarise the above table by grouping together consecutive numbers.

Grouping numbers
Objective 7b: PIVOTing and UNPIVOTing
3 Lectures 17:44

We'll look at creating a PivotTable in Excel, and doing the same thing in SQL Server.


Unfortunately, the PIVOT function creates a lot of NULLs. We'll see how to change them to zero,

Replacing NULLs in PIVOTs.

We'll do the reverse of PIVOT, and unspread columns back into rows.

Objective 7d: CTE statement
2 Lectures 22:00

We'll add a Manager column to the tblEmployee, and find out why we have to a self-join to get the Manager's name.

Preview 09:04

We'll work out the number of bosses an employee has, by using a recursive CTE.

Recursive CTE
Objective 14: Functions
6 Lectures 41:18

We'll have a look at objective 14, and see what we already know (and briefly revisit it).


We'll create our first, basic, function.

Scalar Functions

We'll write a second function, a bit more complicated.

A more complicated scalar function

We'll write a function which uses one SELECT statement to return a table.

Inline Table Function

We'll write a more complex function, creating a table and populating it with the results.

Multi-statement Table Function

We'll "join" the results of a function with a table.

Objectives 6b and 6c: Synonyms and Dynamics
2 Lectures 14:15

We'll create another version of an alias.

Preview 07:26

We'll use a string to create a SELECT statement, and find out how that could be dangerous.

Dynamic SQL
Objectives 8c: GUIDs; and Sequences
4 Lectures 25:01

We'll revisit the IDENTITY default, and see what the disadvantages are.

Preview 03:06

We'll look at the uniqueidentifiers NEWID and NEWSEQUENTIALID, and how to use them.


We'll create a sequence, and look at all the options.

Creating SEQUENCEs

Having created a SEQUENCE, how can we get the next value?

1 Lecture 01:08

We'll review what we have learned in Session 6, and look forward to what we will do in Session 7.

Well done!
About the Instructor
Phillip Burton
4.3 Average rating
3,692 Reviews
50,583 Students
25 Courses
Best Selling Instructor - over 50,000 students so far

Phillip is a Computing Consultant providing expert services in the development of computer systems and data analysis. He is a Microsoft Certified Technology Specialist. He has also been certified as a Microsoft Certified Solutions Expert for Business Intelligence, Microsoft Office 2010 Master, and as a Microsoft Project 2013 Specialist.

He enjoys investigating data, which allows me to maintain up to date and pro-active systems to help control and monitor day-to-day activities. As part of the above, he also developed and maintained a Correspondence Database in Microsoft Access and SQL Server, for viewing job-related correspondence (110,000 pdfs in one job) by multiple consultants and solicitors.

He has also developed expertise and programmes to catalogue and process and control electronic data, large quantities of paper or electronic data for structured analysis and investigation.

He is one of 9 award winning Experts for Experts Exchange's 11th Annual Expert Awards and was one of Expert Exchange's top 10 experts for the first quarter of year 2015.

His interests are working with data, including Microsoft Excel, Access and SQL Server.