Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2009

    Unanswered: MAX(DATE) Shows Irregulare Values

    Hi All

    I am running the below query to try and extract the last date and time that a user entered an activity.

    The list returns the correct date and time BUT
    the Subject is a random row from the database.

    2013-11-19 05:20:45 Dominic,Doyle Battery: 4.05V 30408880

    If a run a complete list of activities from the user and manuall select the latest row i see:

    2013-11-19 05:20:45 Dominic,Doyle Low Battery 34989316

    As you can see the Date/Time is identical, but the Subject and RowID are different.
    Can anyone see what im doing wrong or suggest a better way to do it?


    PHP Code:
    (smsreceived) as Date,
    contacts.firstname as First
    contacts.lastname as Last,
    activities.visiondescription as Subject,
    FROM activitiescontacts 
    WHERE activities
    AND activities.accountid=contacts.accountid
    AND activities.contactid 'AAXA-TGZQY62301'

  2. #2
    Join Date
    Nov 2003
    Provided Answers: 23
    That's because your (non-)use of GROUP BY is invalid SQL - only MySQL chooses to return random data instead of rejecting the query as every other DBMS does.

    Please read these links in order to understand why your aggregation is invalid:

    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags:

    Tips for good questions:

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts