From the course: SQL Server 2008 Essential Training
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Using subqueries - SQL Server Tutorial
From the course: SQL Server 2008 Essential Training
Using subqueries
As you get more comfortable with writing SQL statements, you'll find yourself wanting to combine information from multiple tables more often than not and though a join is a classic way of doing it, it's not the only way. There is another way called a sub- query and let me explain that by kind of taking you step-by-step through the roadmap of how you might get there. So we start with something really simple. We've got a SELECT * statement here. It'll give me everything from SalesOrderHeader. Now if I execute that, I'm getting all the totaling of my sales orders, including things like the customer IDs and the subtotal, and the total due. And I of course can scan this information just fine and look at it, but what if I'm more interested in specific stuff. What about if I want to know information about the biggest order that ever happened? Well, I could, of course, just do something very simple like an ORDER BY. TotalDue, which of course will give it to me ascending which might not be…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
Introduction to Transact-SQL3m 43s
-
Using SELECT statements7m 16s
-
Changing the default database2m 21s
-
Creating conditions in SQL8m 10s
-
Sorting your output3m 23s
-
Using aggregate functions7m 12s
-
Finding unique values2m 14s
-
Joining multiple tables together8m
-
Using subqueries9m 33s
-
Viewing execution plans3m 37s
-
-
-
-
-
-
-
-
-
-