MySQL Forums
Forum List  »  PHP

max row from table
Posted by: Evan Weiner
Date: January 11, 2011 02:42PM

Hello,

I am beating my head against a wall. I'm trying to get the row with the largest punch_in. The query returns the correct punch_in value but returns the id for a different row. Can anyone provide some help?

Thanks,

Evan

Query
SELECT
	id as id,
	max(punch_in) as max_punch_in
FROM
	employees_punches_dev
WHERE
	employees_id = '438'
	AND deleted = 0

Test table
CREATE TABLE `employees_punches_dev` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `employees_id` int(11) NOT NULL DEFAULT '0',
  `punch_in` int(11) NOT NULL DEFAULT '0',
  `punch_out` int(11) NOT NULL DEFAULT '0',
  `punch_lunch` int(11) DEFAULT NULL,
  `net_time` int(11) DEFAULT NULL,
  `employee_punches_files_id` int(11) DEFAULT NULL,
  `added` int(11) NOT NULL DEFAULT '0',
  `deleted` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

INSERT INTO `employees_punches_dev` (`id`, `employees_id`, `punch_in`, `punch_out`, `punch_lunch`, `net_time`, `employee_punches_files_id`, `added`, `deleted`) VALUES
(1, 438, 1294777944, 0, NULL, NULL, NULL, 1294777944, 0),
(2, 438, 1294778043, 0, NULL, NULL, NULL, 1294778043, 0);

Options: ReplyQuote


Subject
Written By
Posted
max row from table
January 11, 2011 02:42PM
January 12, 2011 08:28PM
January 13, 2011 08:39AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.