< Blog

How a “Not Equal To” Query is Processed

How a “Not Equal To” Query is Processed

By Garth Jones

Building on yesterday’s blog post about how a query is processed this post will show you how a query processes the Not Equal To operator.

As I explained in my last post, when a query is run it will process each row within a view or a table. Using the following table as our example, let’s look at the how the Not Equal To operator is processed in a query. This table is comprised of 4 PCs and their add/remove program (ARP) details.

PC Name

PC1

PC2

PC3

PC4

1

Adobe Reader XI

Microsoft Project 2010

Visio 12

Adobe Reader X

2

Visio 12

CorelDraw

ITunes

Microsoft Project 2010

3

ITunes

Office 2010

WordStar

DataStar

4

Microsoft Office 2013

Lotus123

5

Kix 2010

Don’t forget, we’re trying to find all of the PCs that do not have Microsoft Project 2010 installed.

1. Starting at PC1 the query will review each row to look for Microsoft Project 2010.
a. Row 1 is added to the result set since it is not equal to Microsoft Project 2010.
b. Row 2 is added to the result set since it is not equal to Microsoft Project 2010.
c. Row 3 is added to the result set since it is not equal to Microsoft Project 2010.
d. Row 4 is added to the result set since it is not equal to Microsoft Project 2010.

2. The process is repeated for PC2.
a. Row 2 is added to the result set since it is not equal to Microsoft Project 2010.
b. Row 3 is added to the result set since it is not equal to Microsoft Project 2010.

3. The process is repeated with PC3.
a. Row 1 is added to the result set since it is not equal to Microsoft Project 2010.
b. Row 2 is added to the result set since it is not equal to Microsoft Project 2010.
c. Row 3 is added to the result set since it is not equal to Microsoft Project 2010.

4. The process is repeated with PC4.
a. Row 1 is added to the result set since it is not equal to Microsoft Project 2010.
b. Row 3 is added to the result set since it is not equal to Microsoft Project 2010.
c. Row 4 is added to the result set since it is not equal to Microsoft Project 2010.
d. Row 5 is added to the result set since it is not equal to Microsoft Project 2010.

5. Finally the query will return PC1, PC2, PC3 and PC4 to the result set as each of them has a row that is Not Equal To Microsoft Project 2010.

As you can see above the Not Equal To operator will not give us the results that we are looking for, so in next week’s blog post I will show you the importance of using a subselect query.