[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

MySQL Query Syntaz

Posted on 2012-08-25
2
Medium Priority
?
449 Views
Last Modified: 2012-08-25
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;
0
Comment
Question by:hdcowboyaz
  • 2
2 Comments
 

Accepted Solution

by:
hdcowboyaz earned 0 total points
ID: 38333155
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
 

Author Closing Comment

by:hdcowboyaz
ID: 38333158
I figured itout
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month20 days, 12 hours left to enroll

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question