mysql-How to query/modify the record of the maximum date

Source: Internet
Author: User

Reference: Http://stackoverflow.com/questions/6898935/sql-update-query-with-group-by-clause

--Update DataUPDATEProduct_info asTINNER JOIN (SELECTPRODUCT_ID,Max(update_date) Update_date fromProduct_infoWHEREproduct_id= 830 GROUP  byproduct_id) T1 ont.product_id=t1.product_id andT.update_date=t1.update_dateSETIsActive= 1, remark= 'Update operation directly on the shelves---3! ';
--Check the latest recordsSelect *  fromProduct_info asTINNER JOIN (SELECTPRODUCT_ID,Max(update_date) Update_date fromProduct_infoGROUP  byproduct_id) T1wheret.product_id=t1.product_id andT.update_date=T1.update_dateorder by t.product_id;
--The structure of the table usedCREATE TABLE' product_info ' (' product_id ' )INT(Ten) UNSIGNED not NULL, ' Product_Name 'VARCHAR( -) not NULL, ' Cost_price 'DECIMAL(Ten,2) UNSIGNED not NULL DEFAULT '0.00', ' Current_price 'DECIMAL(Ten,2) UNSIGNED not NULL DEFAULT '0.00', ' update_date 'DATETIME  not NULL DEFAULT '2015-01-01 00:00:00', ' Remark 'VARCHAR(255) not NULL DEFAULT "', ' isActive 'TINYINT(1) not NULL DEFAULT '1',    INDEX' idx_id ' (' product_id ')) COMMENT='Product Information Sheet (IsActive Indicates whether the existing product is being sold) \ r \ n This table adds a record to the stock table when new items are added'COLLATE='Utf8_general_ci'ENGINE=InnoDB;

mysql-How to query/modify the record of the maximum date

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.