SQL - Part 2: Sorting


To sort data and gain more experience in the SQL Wizard all while creating an employee photo directory.

Background Information

Assuming you’ve completed the previous tutorial and have a new employee photo directory in the works, you might be wondering “well, this is great and all, but aren’t directories supposed to be sorted by last name or something?” And you are exactly right!! Now we need to figure out how to sort using the SQL Wizard.


Inserting a Tag, ForEach Tag, Out Tag - Displaying Images, SQL - Part 1: Basic Selection

Starting Template

This tutorial is a continuation of the SQL - Part 1: Basic Selection tutorial. We will start off with the template as it is at the end of that tutorial, so if you haven’t already, you should check that tutorial out (it won’t take very long)!


1. Open the SQL Wizard

As with the previous tutorial, we need to open the SQL Wizard again. Do this by selecting the ForEach tag [forEach Employee: and clicking the Wizard button in the AutoTag ribbon.

Show Me How!

2. Drag the items to sort by

We want to sort the tutorial first by last name, and then in the case of two people with the same last name (which there won’t be in this example), then we’ll sort those by first name as well, ascending alphabetically. So to do this, we simply drag the LastName column followed by the FirstName column to the Sort box in the middle. In the sort box, order matters so LastName must be first.

Show Me How!

3. Generate and view results

Finally, generate a document and see what you have created. This step should be very familiar to you by now, but if not, please check out the Inserting a Tag tutorial.

Show Me How!

Quiz Yourself!

Can you sort SQL data in a table in AutoTag?
Yea, just hit the magic “sort” button in the Home ribbon of Microsoft Word after generating my document. Every time I generate it.
No. The only way I can have sorted data in my generated documents is if the data is already sorted.
Yes. All I have to do is drag the columns I want to sort by into the Sort box in the SQL Wizard
Yes, but I have to program it myself which sounds like a daunting task, so no.
True/False: You can only sort by one column. In cases where several rows have the same data in that column, those rows appear together in a random order.
Kind of true. I can sort by two columns, but no more than that.
True. This is an unfortunate limitation that I wish could be amended.
False. I can sort by as many columns in as many ways as I want.
False. After generating the report, I can sort it the rest of the way using Microsoft Word’s magic “Sort” button.


You have completed this tutorial. We recommend taking a look at the SQL - Part 3: Filtering with Static Values tutorial next!