MySQL Query Syntaz

Posted on 2012-08-25
Last Modified: 2012-08-25
On this table I want to select the pcac within a estdetail_id where the pcac_id is max.

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

Doesn't work.....
SELECT MAX(pcac_id), pcac
FROM pcac
WHERE pcac_id = MAX(pcac_id)
GROUP BY estdetail_id;
Question by:hdcowboyaz

    Accepted Solution

    SELECT pc2.pcac_id AS pcac_id, estdetail_id, pcac
    FROM pcac pc
          (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;

    Author Closing Comment

    I figured itout

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    I have been using r1soft Continuous Data Protection ( for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now