Results 1 to 7 of 7
  1. #1
    mithinxavier is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2015
    Posts
    9

    Query not giving required result using max function

    serial rev
    0 0
    0 0
    1303 1
    0 0
    0 0
    0 0
    1306 1
    1301 1
    1308 1
    0 0
    0 0
    0 0
    1295 1
    1296 1
    1297 1
    1283 1
    1283 2
    1300 1
    1299 1
    1302 1
    0 0
    0 0
    0 0
    1012 5
    1304 1
    1305 1
    0 0
    0 0
    0 0
    0 0
    0 0
    1307 1
    1309 1
    1311 1
    1312 1
    1313 1
    1315 1
    1316 1
    1310 1
    0 0
    0 0
    0 0
    0 0
    0 0
    1500 2A
    1500 2B
    1500 1

    my code

    SELECT projectDetails.serial, Max(projectDetails.rev) AS MaxOfrev
    FROM projectDetails
    GROUP BY projectDetails.serial
    HAVING (((projectDetails.serial)<>0))
    ORDER BY projectDetails.serial;


    result :

    serial MaxOfrev
    1012 5
    1283 2
    1295 1
    1296 1
    1297 1
    1299 1
    1300 1
    1301 1
    1302 1
    1303 1
    1304 1
    1305 1
    1306 1
    1307 1
    1308 1
    1309 1
    1310 1
    1311 1
    1312 1
    1313 1
    1315 1
    1316 1
    1500 2B




    Desired Result

    serial MaxOfrev
    1012 5
    1283 2
    1295 1
    1296 1
    1297 1
    1299 1
    1300 1
    1301 1
    1302 1
    1303 1
    1304 1
    1305 1
    1306 1
    1307 1
    1308 1
    1309 1
    1310 1
    1311 1
    1312 1
    1313 1
    1315 1
    1316 1
    1500 2A
    1500 2B

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    The query is working properly. 2B is greater than 2A. And 3A would be greater than 2B.

    Also, because this is a text field, 2 would be greater than 11.

    That's what happens when you mix alpha and numeric.
    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
    mithinxavier is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2015
    Posts
    9
    Quote Originally Posted by June7 View Post
    The query is working properly. 2B is greater than 2A. And 3A would be greater than 2B.

    Also, because this is a text field, 2 would be greater than 11.

    That's what happens when you mix alpha and numeric.
    How can i solve this issue

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Not easily. How many different alpha values are there - A thru Z? Never more than 1 alpha? Does number part ever exceed 9?
    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.

  5. #5
    mithinxavier is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2015
    Posts
    9
    Number part will be less than 9 only and alpha max up to d

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Wait, just took another look at your desired results. Why is that 1500 2B showing at end of post? You want both 2A and 2B records? If not, consider:

    Query1:
    SELECT projectDetails.Serial, projectDetails.rev, Val([rev]) AS N, Mid([rev],2) AS A
    FROM projectDetails;

    Query2:
    SELECT * FROM Query1 WHERE Serial & rev IN (SELECT TOP 1 Serial & rev FROM Query1 AS Dupe WHERE Dupe.Serial = Query1.Serial ORDER BY Dupe.N DESC, Dupe.A ASC)
    AND Serial<>'0' ORDER BY Serial;
    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.

  7. #7
    mithinxavier is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2015
    Posts
    9
    Thank you i solve the issue

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

Similar Threads

  1. Replies: 5
    Last Post: 01-30-2015, 08:57 PM
  2. Replies: 7
    Last Post: 08-23-2014, 05:52 AM
  3. FileCopy Funtion
    By dccjr in forum Programming
    Replies: 2
    Last Post: 04-18-2013, 09:04 PM
  4. Access giving wrong result using sql query
    By amlanroy in forum Access
    Replies: 3
    Last Post: 05-10-2012, 10:11 AM
  5. Random Rdn() Funtion Help Please
    By graviz in forum Access
    Replies: 1
    Last Post: 12-09-2009, 11:57 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