Results 1 to 6 of 6
  1. #1
    pault is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    3

    Question Query moves - Last location of tube

    Hi. Please, could you help me with easy query? I have database with three tables - Tubes, Moves and Locations. I would like to build query which will list all tubes with their last locations from table moves. I've attached tables and their relations.



    Click image for larger version. 

Name:	Tubes.png 
Views:	8 
Size:	8.7 KB 
ID:	13852

    Description of database:
    I have tubes with unique ID, which can be moved from one location to another locaion several times. These moves are recorded to the table 'Moves'. Table 'Locations' is simple table with list of locations.

    I would appreciate any ideas or redirection.

    Regards,
    Tomas

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Try TOP parameter for one approach. Review: Microsoft Access tips: Subquery basics
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Does this work for you?

    Most recent value
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    pault is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    3
    Thank you pbaldy!
    It helped me. I've built this two SQL queries:

    SELECT Max(Moves.DateMove) AS MaxDate, TubeID
    FROM Moves
    GROUP BY Moves.TubeID;


    SELECT L.LocationName, T.TubeBarcode
    FROM Moves AS M, MovesMaxDates AS Q, Tubes AS T, Locations AS L
    WHERE M.TubeID = Q.TubeID AND M.LocationID = L.LocationID AND T.TubeID = M.TubeID AND M.DateMove = Q.MaxDate
    ORDER BY T.TubeBarcode;

    Many Thanks
    Tomas

  5. #5
    pault is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    3
    Hi June7.
    That is nice approach. I cannot make functional subquery in my Access, but the SQL "SELECT TOP 1 FROM X ORDER BY X.Y DESC" works.

    Thank you.
    Tomas

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help Tomas, and welcome to the site! I would use the JOIN rather than the WHERE clause, but that's me.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 06-04-2013, 09:51 AM
  2. Replies: 3
    Last Post: 05-08-2013, 01:29 PM
  3. Replies: 0
    Last Post: 03-01-2011, 10:47 AM
  4. Replies: 5
    Last Post: 06-29-2010, 06:10 AM
  5. txtbox moves everything else down
    By cowboy in forum Access
    Replies: 2
    Last Post: 01-06-2010, 05:45 PM

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