Results 1 to 2 of 2
  1. #1
    sandum150 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Posts
    1

    SQL Query

    Hello everybody!


    I had created a query with follow SQL:
    SELECT clienti.nume_client, tracker.id_tracker, tracker.SIM, abonamente.[data achitarii], abonamente.data_expirarii
    FROM tracker INNER JOIN (clienti INNER JOIN abonamente ON clienti.[ID] = abonamente.[client]) ON tracker.[ID] = abonamente.[tracker];

    But I need 2 conditions:
    1. Each tracker.id_tracker should be distinct
    2. abonamente.data_expirarii should be the maximum (biggest value)

    That's the structure of my db
    Click image for larger version. 

Name:	reationship.jpg 
Views:	19 
Size:	50.4 KB 
ID:	12324
    Thank You!

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    this is a relationship diagram not a SQL statement.

    If you are looking for the most recent data_expirarii for each client and showing information related to that record you have to do a 2 step query.

    The easiest way to do that is to create a query that shows your client and their most recent data_expirarii first

    this query will give you that:

    Code:
    SELECT Max(abonamente.Data_Expirarii) AS MR_Exp, abonamente.Client
    FROM abonamente
    GROUP BY abonamente.Client;
    From there you would link this 'pre' query to your abonamente table linking on both the client and data_expirarii fields.

    Assuming you only have on record in your abonamente table for each data_expirarii you should be able to get the data you want.

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

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