Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2012
    Thanked 3 Times in 3 Posts

    Confusion about MAX in query

    I have set up the following query.
    PHP Code:
    SELECT MAX(businessInfo.id) AS refIDbusinessInfo.id AS checkID
    FROM businessInfomembers
    WHERE businessInfo
    .memberID members.id 
    AND members.membershipType 'CORP'
    GROUP BY members.business
    ORDER BY members
    .business ASC 
    Where this goes wrong is that the businessInfo.businessWebsite is not being delivered from the MAX(businessInfo.id) row. I put the 'checkID in to return the id number for the row being returned. The table looks like this:

    What am I missing?

    By way of explanation of the need, we need to keep a record of all the changes in business info on the database so each time a change is made a new entry is made.
    Last edited by rgEffects; 11-03-2013 at 03:19 PM.

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Denver, Colorado USA
    Thanked 304 Times in 296 Posts
    If you want the actual row holding a specific value within the group, see this - http://dev.mysql.com/doc/refman/5.0/...group-row.html

    Just using MAX() gives you the maximum value for that column within the group, not the row it is in.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


    Posting Permissions

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