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

Using subqueries - SQL Server Tutorial

From the course: SQL Server 2008 Essential Training

Start my 1-month free trial

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…

Contents