MySQL Query Syntaz

On this table I want to select the pcac within a estdetail_id where the pcac_id is max.

CREATE TABLE `pcac` (
  `pcac_id` mediumint(10) NOT NULL AUTO_INCREMENT,
  `estdetail_id` mediumint(10) unsigned NOT NULL DEFAULT '0',
  `pcac` decimal(11,2) DEFAULT '0.00',
  PRIMARY KEY (`pcac_id`)
) ENGINE=MyISAM AUTO_INCREMENT=4383 DEFAULT CHARSET=latin

Doesn't work.....
SELECT MAX(pcac_id), pcac
FROM pcac
WHERE pcac_id = MAX(pcac_id)
GROUP BY estdetail_id;
hdcowboyazAsked:
Who is Participating?
 
hdcowboyazConnect With a Mentor Author Commented:
SELECT pc2.pcac_id AS pcac_id, estdetail_id, pcac
FROM pcac pc
JOIN
      (SELECT MAX(pcac_id) AS pcac_id
      FROM pcac
      GROUP BY estdetail_id
      ORDER BY estdetail_id ASC
      ) AS pc2 ON pc2.pcac_id = pc.pcac_id
ORDER BY estdetail_id ASC;
0
 
hdcowboyazAuthor Commented:
I figured itout
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.