Results 1 to 5 of 5
  1. #1
    yosik20 is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2011
    Location
    madagascar
    Posts
    5

    Extract two last recodes

    Extract two last recodes
    Question regarding one to many relationship query
    1. I have main table, lets say 'authors', and another table, lets say 'books'. The relationship is one-to-many (many books for one author – connected by author id).

    2. I want to create a query (for a report) that extract the author and his last 2 books (referenced for example by book date).
    How can I do it? (assuming there are authors with more or less books than 2)



    Thanks all!

  2. #2
    Rixxe is offline Blessed Bear
    Windows 7 Access 2007
    Join Date
    Sep 2010
    Location
    London (Essex ... yep!)
    Posts
    184
    I think you might need something like:

    SELECT TOP 2 AuthID, Author, Book, MAX(Date) as MaxDate
    FROM Author AS b INNER JOIN Books AS a
    ON a.AuthID = b.AuthID
    WHERE Author = 'John Smith'
    ORDER BY Book
    GROUP BY AuthID, Author, Book

    Somethings probably wrong or slightly off, so try it out and change at will.

    Good Luck.

  3. #3
    yosik20 is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2011
    Location
    madagascar
    Posts
    5
    thanks, Works Great!
    One more thing - the Output now is tabular. How can I generate it as one line per author. where the 2 last book are in the same line...

  4. #4
    Rixxe is offline Blessed Bear
    Windows 7 Access 2007
    Join Date
    Sep 2010
    Location
    London (Essex ... yep!)
    Posts
    184
    You are welcome.

    You want something like:

    Author || Book1 || Book2

    Erm, Oddly enough i've never had to do it, I do remember seeing someone last week on this site asking for the same thing, and getting a response.
    I'll see if i can find it, if not google your heart out!

    Good Luck.

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    There is a concatenation function here, that may be hepful.

    http://www.mvps.org/access/modules/mdl0004.htm

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

Similar Threads

  1. Extract data at end of cell
    By madsc1 in forum Access
    Replies: 2
    Last Post: 03-21-2011, 04:12 PM
  2. Extract Partial Data
    By madsc1 in forum Access
    Replies: 6
    Last Post: 03-16-2011, 03:43 PM
  3. Extract Creation/Last Edit Date
    By jgelpi16 in forum Programming
    Replies: 2
    Last Post: 02-15-2011, 07:12 AM
  4. Extract Text Data
    By tmcrouse in forum Queries
    Replies: 5
    Last Post: 05-25-2010, 11:34 AM
  5. extract text from memo
    By lions1855 in forum Queries
    Replies: 2
    Last Post: 05-03-2010, 07:28 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