Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Find missing records in one table excluding cancelled items

Posted on 2016-08-25
4
Medium Priority
?
72 Views
Last Modified: 2016-08-25
Hi, I need to find all entries in table Hotelogix which are not existing in table Reservations but excluding cancelled records in Reservations. I have tried the following statement:

SELECT HotelogixReservations.[Group Id], HotelogixReservations.[Guest Name]
FROM HotelogixReservations LEFT JOIN QueryFull ON Ltrim(Rtrim(HotelogixReservations.[Group ID])) = QueryFull.[Group Reservation No]
WHERE (((QueryFull.[Group Reservation No]) Is Null)) OR QueryFull.Cancel=TRUE;

This almost works but gives an error in the case where I have the same reservation in Reservations table twice (once as cancelled and once as an open one). Not sure how to exclude any cancelled records in reservation? Thank you for any help..
0
Comment
Question by:mpim
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 1

Accepted Solution

by:
rquaglia earned 2000 total points
ID: 41770355
Hi!
looking at you question I suggest to try something like:
SELECT HotelogixReservations.[Group Id], HotelogixReservations.[Guest Name]
FROM HotelogixReservations
WHERE Ltrim(Rtrim(HotelogixReservations.[Group ID])) NOT IN (select [Group Reservation No] from QueryFull where Cancel<>TRUE);

Sorry, I can't try this but anyway I hope this helps.
0
 
LVL 41

Expert Comment

by:Sharath
ID: 41770457
Can you provide some sample data and expected result?
0
 
LVL 39

Expert Comment

by:PatHartman
ID: 41770612
The problem with your initial query is the criteria against the "right" table.  The subselect solves that problem.  However, if you are running the query in Access subselects are not well optimized so you could make a query that selects the "right" table and applies the criteria.  Then left join to that query.  Access would then apply the criteria to the "right" table PRIOR to performing the left join and that solves the problem.
1
 

Author Closing Comment

by:mpim
ID: 41770702
Great help! Thank you Michael
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question