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);