If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Missing records in query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-27-10, 16:52
Janet Bearne Janet Bearne is offline
Registered User
 
Join Date: Aug 2003
Location: Londo, UK
Posts: 20
Missing records in query

Hi. I have a database with three tables, all in a relationship. This is the SQL from the query

SELECT tblBook.BookID AS tblBook_BookID, tblBook.Book, tblBook.Price, tblBook.Frequency, tblName.NameID AS tblName_NameID, tblName.Fname, tblName.Surname, tblName.TelNo, tblOrder.ID, tblOrder.NameID AS tblOrder_NameID, tblOrder.[No], tblName.Cancelled
FROM tblName INNER JOIN (tblBook INNER JOIN tblOrder ON tblBook.BookID = tblOrder.BookID) ON tblName.NameID = tblOrder.NameID
ORDER BY tblName.Surname;

What I am finding is that not all the records are showing in the query. From looking at previous posts and at this tutorial SQL Tutorial [SELECT Statement Extended] I think it may be something to do with the Join function. Perhaps it should be FULL OUTER JOIN? But I am not sure how to code this to replace the two join statements above. If I replace INNER JOIN with FULL OUTER JOIN an error message says Syntax error and highlights OUTER.

Perhaps someone can explain this to me.
__________________
Janet
Reply With Quote
  #2 (permalink)  
Old 01-27-10, 17:17
nckdryr nckdryr is offline
Computer Monkey
 
Join Date: May 2005
Posts: 1,191
It appears your tutorial site you linked to does a decent enough job of explaining the differences, but I don't think Access supports a Full Outer Join; I think you'll want either a LEFT JOIN or a RIGHT JOIN.
__________________
Me.Geek = True
Reply With Quote
  #3 (permalink)  
Old 01-27-10, 17:29
Janet Bearne Janet Bearne is offline
Registered User
 
Join Date: Aug 2003
Location: Londo, UK
Posts: 20
OK. So I tried LEFT OUTER JOIN and LEFT JOIN (as you suggested nckdryr) both gave the error message "Join expression not supported".

If that is the case, how do I get these records visible?
__________________
Janet
Reply With Quote
  #4 (permalink)  
Old 01-27-10, 17:38
Janet Bearne Janet Bearne is offline
Registered User
 
Join Date: Aug 2003
Location: Londo, UK
Posts: 20
I've just seen your reference to the ACCESS tutorial on joins. I have tried what they suggest, but it is telling me I need to create a query on one join and then insert it into the other query with the other join. I shall have to have a go at that tomorrow. I am not sure how to do it, but I will give it a try.
__________________
Janet
Reply With Quote
  #5 (permalink)  
Old 01-27-10, 17:48
nckdryr nckdryr is offline
Computer Monkey
 
Join Date: May 2005
Posts: 1,191
Try something like the following:

Code:
SELECT tblBook.BookID AS tblBook_BookID, tblBook.Book, tblBook.Price, tblBook.Frequency, tblName.NameID AS tblName_NameID, tblName.Fname, tblName.Surname, tblName.TelNo, tblOrder.ID, tblOrder.NameID AS tblOrder_NameID, tblOrder.[No], tblName.Cancelled
FROM tblName LEFT JOIN (tblBook LEFT JOIN tblOrder ON tblBook.BookID = tblOrder.BookID) ON tblName.NameID = tblOrder.NameID
ORDER BY tblName.Surname;
See if that gets you what you're after.
__________________
Me.Geek = True
Reply With Quote
  #6 (permalink)  
Old 01-28-10, 10:42
Janet Bearne Janet Bearne is offline
Registered User
 
Join Date: Aug 2003
Location: Londo, UK
Posts: 20
Tried that and the error "Join expression not supported" comes up
__________________
Janet
Reply With Quote
  #7 (permalink)  
Old 01-28-10, 10:50
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Code:
  FROM (
       tblOrder
INNER
  JOIN tblBook
    ON tblBook.BookID = tblOrder.BookID
       )
INNER 
  JOIN tblName 
    ON tblName.NameID = tblOrder.NameID


they ~have~ to be INNER joins, unless you have a situation where (1) there's an order with a BookID for a non-existent book, or (2) there's an order with a NameID for a non-existent name
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #8 (permalink)  
Old 01-28-10, 11:01
Janet Bearne Janet Bearne is offline
Registered User
 
Join Date: Aug 2003
Location: Londo, UK
Posts: 20
BINGO. That worked. Many thanks.

It is basically the same as I had originally but with the brackets in a different place.

'Tis a puzzlement!
__________________
Janet
Reply With Quote
  #9 (permalink)  
Old 09-01-10, 10:13
sebtus sebtus is offline
Registered User
 
Join Date: Sep 2010
Posts: 1
MS Access 2007 - Query problem

I have a similar problem as mentioned above and the solution does not work for me. I have two tables; one of them has 1400 records and another about 100. It seems that very randomly, query does not give the record I call for,
Here is the SQL code for my query. Please give me any idea what is wrong or what should I change to make it work. MS Access 2007

Code:
SELECT MasterListing.OWC, MasterListing.ID, MasterListing.PartNumber, MasterListing.SerialNumber, MasterListing.WUC, MasterListing.DateDueCal, MasterListing.DateLastCal, MasterListing.Location, MasterListing.Comments, MasterListing.Nomenclature, MasterListing.JobControl, MasterListing.CalInterval, MasterListing.DateFromPmel, Master_PN.PartNumber, Master_PN.Nomenclature, Master_PN.CalInterval, Master_PN.LastUpdate, Master_PN.Remarks, Master_PN.WUC, MasterListing.Status, MasterListing.DateToOWC
FROM MasterListing INNER JOIN Master_PN ON MasterListing.PartNumber = Master_PN.PartNumber
WHERE (((MasterListing.ID)=[Enter ID]));
Reply With Quote
Reply

Tags
join, query

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On