Results 1 to 4 of 4
  1. #1
    af193 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2016
    Location
    Ottawa, ON. Canada
    Posts
    2

    Question SQL statement in one table

    Hello;


    I am new with MS Access and MS Access is the only tool I have now. I want to write a select SQl statement where the output is the maximum effective date of all records.


    The data lay out as below

    TABLE

    ID EFFDT
    1 25-05-2015
    1 18-04-2015
    1 22-05-2015
    2 12-03-2015
    2 11-02-2015
    2 10-01-2016

    I want the output as below:

    ID EFFDT
    1 25-05-2015
    2 10-01-2016

    I would write the sql like below (Oracle SQL standard ) but syntax is not accept by MS Access. How to translate this SQl into MS Access acceptable .

    /* note that there is only one table name = TABLE , in Oracle SQL language A & B here are used as reference
    Select A.ID, A.EFFDT from TABLE A where A.EFFDT = MAX(Select B.EFFDT from TABLE B where B.ID = A.ID);

    Thank you

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Access has a nice query builder that will create this code for you. Simply do the following:

    1. Create a new query in Query Designer
    2. Add your table in the Query Builder
    3. Add the two fields in the Query Builder
    4. Click on the Totals button in the Query Designer toolbar (looks like a Sigma)
    5. This will add a "Totals" row under each field. In the Totals row for the EFFDT field, change the phrase "GROUP BY" to "MAX".
    6. View your results

    If you wish to see what the SQL code for this query looks like, change the query to SQL View. You can also use SQL View to write your code directly if you do not like using the Query Builder.

  3. #3
    af193 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2016
    Location
    Ottawa, ON. Canada
    Posts
    2
    it worked...thank you

  4. #4
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You are welcome!

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

Similar Threads

  1. Replies: 21
    Last Post: 04-22-2016, 04:19 PM
  2. WHERE statement in table
    By pyromaniac511 in forum Queries
    Replies: 5
    Last Post: 04-09-2016, 02:56 AM
  3. If statement to read from table
    By ekulrenlig in forum Macros
    Replies: 4
    Last Post: 09-19-2015, 08:21 PM
  4. Replies: 1
    Last Post: 10-15-2012, 02:41 PM
  5. IIF statement too complex, table instead?
    By Lauren1989 in forum Queries
    Replies: 3
    Last Post: 01-25-2012, 01:27 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