Results 1 to 4 of 4
  1. #1
    Nouri31 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2011
    Posts
    3

    Can't get the logic right.

    Hi, I have been working on this problem all day and I cant get the logic right. we are asked "Given a specific taxi, list its history – drivers, accidents, mileage "



    The SQL that I am using for this query is shown below:

    SELECT Driver.[Driver ID], Rental.[Mile Out], Taxi.[Taxi ID], Taxi.Manufacturer, Taxi.[Date of Purchase], Taxi.[Accident Occurence]
    FROM Taxi INNER JOIN (Driver INNER JOIN Rental ON Driver.[Driver ID] = Rental.[Driver ID]) ON Taxi.[Taxi ID] = Rental.[Taxi ID]
    WHERE (((Taxi.[Taxi ID])=[Enter Taxi ID Number]));

    I'm pulling the data from 3 different tables, this query works when the taxi has been rented out, however when taxi has no Rental ID the query doesnt show any other informations such as Date of Purchase or Manufacturer. I am told that the problem is "Taxi INNER JOIN (Driver INNER JOIN Rental ON Driver.[Driver ID] = Rental.[Driver ID]) ON Taxi.[Taxi ID] = Rental.[Taxi ID]" statement.

    What i want to know is how to pull data based on information needed even though the taxi has not been rented by anyone else. Any help would be appreciated.

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You will need 2 queries to do this. First create a query that joins the rental and driver tables; something like this:


    query name: qryDriverRentalInfo
    SELECT Rental.[Mile Out], Rental.[Driver ID], Rental.[Taxi ID]
    FROM Driver INNER JOIN Rental ON Driver.[Driver ID] = Rental.[Driver ID];

    Now create another query that joins the taxi table to the above query, you will need to alter the join type to include all records from the Taxi table and those records from the above query that match this would be a LEFT JOIN

    SELECT Taxi.[Taxi ID], Taxi.Manufacturer, Taxi.[Accident Occurence], Taxi.[Date of Purchase], qryDriverRentalInfo.[Mile Out], qryDriverRentalInfo.[Driver ID]
    FROM Taxi LEFT JOIN qryDriverRentalInfo ON Taxi.[Taxi ID] = qryDriverRentalInfo.[Taxi ID];

  3. #3
    Nouri31 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2011
    Posts
    3
    Hi jzwp11,

    thank you so much. worked like a charm.

  4. #4
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You're welcome; glad we could help.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Relationship Logic
    By Huddle in forum Access
    Replies: 2
    Last Post: 01-25-2011, 04:27 PM
  2. Logic statement to select report
    By AKQTS in forum Reports
    Replies: 7
    Last Post: 07-30-2010, 12:52 PM
  3. Help a noob (calculating fields and logic)
    By unnamedplayer in forum Reports
    Replies: 9
    Last Post: 07-16-2010, 10:28 AM
  4. Need help with code logic/consolidation
    By bg18461 in forum Programming
    Replies: 1
    Last Post: 03-31-2010, 04:19 PM
  5. Split database logic
    By Overdive in forum Database Design
    Replies: 3
    Last Post: 02-05-2010, 08:22 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