Home Case Studies MS Office Tips and Tricks Sample Code Helpful Videos Custom Development  Custom Training Join Us Contact Us
Search Our Site:  

Inequality Joins In Access

For most of our queries, we join tables based on a column in one table exactly matching a column in another table. For instance, we can retrieve a customer’s contact information from one table and their order history from another table based on a matching customer id number.

SQL Server and many other industrial strength databases also support queries where columns do not match—one field is greater than the other or between two values in the foreign table’s record. These types of joins are called inequality joins or non-equijoins.

Take an example of a company that is trying to find orders that were improperly placed. For whatever reason, some customers are being allowed to place orders in excess of their credit limit. We need to search the customers table and the orders table for these occurrences. We join the two tables on customer ID—that much is standard. But we also join them on the inequality relationship (less than, in this case) of the customer credit line and the order amount. If you are used to SQL, this will look familiar, if not exactly standard, to you:

SELECT Customers.FirstName, Customers.LastName, Customers.CreditLine, Orders.TotalAmount FROM Customers INNER JOIN Orders ON Customers.CustID = Orders.CustID AND Customers.CreditLine < Orders.TotalAmount

We are using the less than operator in a JOIN statement!

Are You Ready For Office 365?


Office 365 is

  • Email and calendaring powered by Microsoft Exchange
  • Office Web Apps - the office productivity apps you already know, tailored for the web
  • Websites powered by Microsoft SharePoint both for internal-facing intranet and customer-facing website
  • Instant Messaging and Online Meetings powered by Microsoft Lync
  • All with a financially-backed 99.9% uptime guarantee

Sign up for a free trial:

Name
Company
Email Address

Your information will not be shared with any other party. You must provide a valid email in order to recieve your login information and starting information kit.

Watch this video  to see how Office 365 can help your business.

Access will allow this query in the SQL window and will return the correct results, but if you try to view it the query design window, this is what you see:



If you like to work in the Query Design window, you can set up the inequality in the WHERE clause instead of the FROM clause like so:

SELECT Customers.FirstName, Customers.LastName, Customers.CreditLine, Orders.TotalAmount FROM Customers INNER JOIN Orders ON Customers.CustID = Orders.CustID
WHERE Customers.CreditLine< Orders.TotalAmount


The difference in speed of the two queries depends on the flavor of SQL you’re running, but the results will be identical. See our prior articles on Access Subqueries, Using SQL In Access and Cross Joins in Access for more about SQL and Access.
 
Please share your comments on this article!

 
Name (opt)
Email Address (opt)
Your Questions/
Comments

I Get It! Development does not share your email address or other information, nor do we add you to any mailing lists unless you specifically request to be added by checking the box below.



SEE ALSO
You may also find the following articles useful:

Subqueries In Access

SQL In Access

SQL Cross Join In Access

Access And Uses For Union

One-To-One Relationships In Access

Spreadsheet vs. Database

Bound vs Unbound Forms

Excel - Access Import Problems

Columns In Access

Spreadsheet View (Access)

Access To Excel And Back

VBA Functions In Access

Ssheets vs Dbase Round 2

Control Your Data!

Compact/Repair In Access

References

Journal of Accountancy Articles

Tweaking The Numbers

Block That Spreadsheet Error

Excel Security Issues


 

Clients

Do you need help with Microsoft Office? Contact us

See how we've helped companies like yours develop effective business processes

Client Success Stories


 

Consultants

I Get It! Consultants set their own hours, work with their own clients, and choose their own projects.

If you're a Microsoft Office guru and would like to explore being a full-time consultant, please see our consultant information pages.