Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    ShaunG is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jan 2018
    Posts
    237

    Querys returning different data

    My Querys are returning the wrong data, the sql and joins are the problem.

    I changed from inner joins to right outer joins to begin with to retrieve data if there was null data in builder or supervisor fields, but I was sorta shooting in the dark.



    ive done some reading and still not quite getting my head around the joins and how they work, if some could explain it using my sql as an example would be great, thanks.

    SELECT tblBuilders.BuilderID_PK, tblBuilders.BuilderName, tblBuilders.ContactNumber, tblSiteSupervisor.SupervisorID_PK, tblSiteSupervisor.FirstName, tblSiteSupervisor.LastName, tblSiteSupervisor.ContactNumber, tblJobDetails.JobNoID_PK, tblJobDetails.SiteBusiness_Name, tblJobDetails.ClientsFirst_Name, tblJobDetails.Last_Name, tblJobDetails.Ph_No_1, tblJobDetails.Ph_No_2, tblJobDetails.StreetNum, tblJobDetails.Suburb, tblJobDetails.DateEntered, tblJobDetails.StreetName
    FROM (tblBuilders RIGHT OUTER JOIN tblSiteSupervisor ON tblBuilders.BuilderID_PK = tblSiteSupervisor.BuilderID_FK) RIGHT OUTER JOIN tblJobDetails ON tblSiteSupervisor.SupervisorID_PK = tblJobDetails.SiteSupervisorID_FK
    ORDER BY tblJobDetails.JobNoID_PK DESC;

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Not enough information - what results do you want to get from this query? All jobs? All clients? What is "wrong data"?

  3. #3
    ShaunG is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jan 2018
    Posts
    237
    Quote Originally Posted by aytee111 View Post
    Not enough information - what results do you want to get from this query? All jobs? All clients? What is "wrong data"?
    The data in the tables dont match the data in query...

    in the table job 28 belongs to builder (A) but in the query it belongs to Builder(B)

    the query is suppose to pullup up the job details with or with out builders, but if theres builders involved there details with the supervisor details pulled up as well.

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    So - all jobs, then an outer join to supervisors table, same join from there to builders table. In the query design window, right-click on the line linking to the tables and select the option "all records from jobs and only the records from supervisors that match". Do the same for the link between supervisors and builders.

  5. #5
    ShaunG is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jan 2018
    Posts
    237
    Click image for larger version. 

Name:	Untitled11.jpg 
Views:	13 
Size:	163.1 KB 
ID:	32479Click image for larger version. 

Name:	Untitled12.jpg 
Views:	13 
Size:	164.8 KB 
ID:	32480

    had a look and it, looks like thats already done

  6. #6
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    From the SQL in your first post, it looks like you typed that in, not Access. Remove the links and relink the tables, let Access create the SQL for you.

  7. #7
    ShaunG is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jan 2018
    Posts
    237
    Quote Originally Posted by aytee111 View Post
    From the SQL in your first post, it looks like you typed that in, not Access. Remove the links and relink the tables, let Access create the SQL for you.
    nahh Access typed it I adjusted the type of join that's it...

    Ill redo as you've said and see how I go

  8. #8
    ShaunG is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jan 2018
    Posts
    237
    Quote Originally Posted by aytee111 View Post
    From the SQL in your first post, it looks like you typed that in, not Access. Remove the links and relink the tables, let Access create the SQL for you.
    redone the links and changed the settings to suit my post #4 and still different details from table to query, its seems to be allocating the same builder to all the jobs when 3 different builders being used at the moment.

  9. #9
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Post the SQL.

  10. #10
    ShaunG is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jan 2018
    Posts
    237
    Quote Originally Posted by aytee111 View Post
    Post the SQL.
    SELECT tblJobDetails.JobNoID_PK, tblJobDetails.SiteBusiness_Name, tblJobDetails.ClientsFirst_Name, tblJobDetails.Last_Name, tblJobDetails.Ph_No_1, tblJobDetails.Ph_No_2, tblJobDetails.StreetNum, tblJobDetails.StreetName, tblJobDetails.Suburb, tblJobDetails.DateEntered, tblSiteSupervisor.FirstName, tblSiteSupervisor.LastName, tblSiteSupervisor.ContactNumber, tblBuilders.BuilderName, tblBuilders.ContactNumber
    FROM (tblBuilders RIGHT JOIN tblSiteSupervisor ON tblBuilders.BuilderID_PK = tblSiteSupervisor.BuilderID_FK) RIGHT JOIN tblJobDetails ON tblSiteSupervisor.SupervisorID_PK = tblJobDetails.SiteSupervisorID_FK;

  11. #11
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    This works for me, so without seeing your data I am not sure where to go from here. I suggest you do these one at a time, first create a query with all the jobs and their supervisors. When that works, create a query with supervisors and their buildings. Maybe you can track down where the problem is occurring.

  12. #12
    ShaunG is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jan 2018
    Posts
    237
    Quote Originally Posted by aytee111 View Post
    This works for me, so without seeing your data I am not sure where to go from here. I suggest you do these one at a time, first create a query with all the jobs and their supervisors. When that works, create a query with supervisors and their buildings. Maybe you can track down where the problem is occurring.
    yeah to easy ill create a few more querys and go from there, cheers for the help.

  13. #13
    ShaunG is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jan 2018
    Posts
    237
    Quote Originally Posted by aytee111 View Post
    This works for me, so without seeing your data I am not sure where to go from here. I suggest you do these one at a time, first create a query with all the jobs and their supervisors. When that works, create a query with supervisors and their buildings. Maybe you can track down where the problem is occurring.
    and works for me when I recreate it..... whats the deal does my head in. thanks again

  14. #14
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Good old MS, up to their tricks again!!

  15. #15
    ShaunG is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jan 2018
    Posts
    237
    Quote Originally Posted by aytee111 View Post
    Good old MS, up to their tricks again!!
    lol I stand corrected again its up shit creek... Arhh gotta love it

    well that's me for tonight

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 16
    Last Post: 01-29-2018, 03:12 PM
  2. Query not returning certain data...
    By mgillespie21234 in forum Queries
    Replies: 7
    Last Post: 10-17-2014, 03:39 PM
  3. Union Query Returning Different Data
    By deluga.69 in forum Queries
    Replies: 2
    Last Post: 08-15-2011, 01:47 PM
  4. Queries not returning data
    By Verso in forum Queries
    Replies: 1
    Last Post: 08-11-2011, 01:46 AM
  5. Simple Query not returning any data.
    By psoli in forum Queries
    Replies: 4
    Last Post: 06-16-2011, 11:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums