I'm an MySQL noob, so please bear with me. I have two tables: TABLE `attendees` ( `attendeeid` int(10) unsigned NOT NULL AUTO_INCREMENT, `fname` varchar(20) NOT NULL, `lname` varchar(20) NOT NULL, `dojid` varchar(10) NOT NULL, `address1` varchar(25) NOT NULL, `address2` varchar(25) NOT NULL, `city` varchar(20) NOT NULL, `state` char(2) NOT NULL, `zipcode` varchar(5) NOT NULL, `phonenumber` varchar(15) NOT NULL, `memberid` int(10) unsigned NOT NULL, PRIMARY KEY (`attendeeid`), KEY `memberid` (`memberid`), CONSTRAINT `attendees_ibfk_2` FOREIGN KEY (`memberid`) REFERENCES `members` (`memberid`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; TABLE `history` ( `historyid` int(10) unsigned NOT NULL AUTO_INCREMENT, `amount` float NOT NULL, `subsidy` char(1) NOT NULL, `last_payment` date NOT NULL, `amount_paid` float NOT NULL, `balance` float NOT NULL, `attendeeid` int(10) unsigned NOT NULL, `memberid` int(10) unsigned NOT NULL, PRIMARY KEY (`historyid`), KEY `attendeeid` (`attendeeid`), CONSTRAINT `history_ibfk_2` FOREIGN KEY (`attendeeid`) REFERENCES `attendees` (`attendeeid`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; Code (markup): What I'm trying to do is retrieve fields from History table using MAX(historyid) to find the latest info entered for an attendee, using the Attendee table for the name, join the two tables with attendeeid. My query looks like this: select * select a.attendeeid,max(h.historyid),a.fname,a.lname,h.last_payment,h.balance history JOIN attendees AS a ON a.attendeeid = h.attendeeid group by a.attendeeid) as maxHistoryPerAttendee where attendeeid = 29 Code (markup): The problem is that, while it sure 'nuff gets the MAX(historyid) right, the row it pulls from is the very first row entered in History for that attendee. I need last_payment and balance to be associated with the MAX(historyid) row, not the row with lowest historyid. Like I said, I'm new to MySQL. I've been online all day, reading this, reading that, and I've probably seen what I need and just didn't know it. Just need a little help here, guys. Thank you.
how about something like SELECT TOP 1 * FROM attendees, history WHERE (attendees.attendeeid = history.attendeeid) AND (attendees.attendeeid = 29) ORDER BY history.historyid DESC