简体   繁体   中英

query for Select distinct rows and maximum of auto generated test id?

在此处输入图片说明 this is my table manufacture_data .I need to get all data of distinct manufacture_name and maximum of test_id for each. that means i need to get row with test id 4 and 6.

can anyone help?

SELECT *
FROM (
SELECT *  from manufacture_data    
ORDER BY Test_id DESC
) t
GROUP BY t.`manufacture_name`

Try this :

SELECT  Test_id  from manufacture_data 
WHERE Test_id IN ( SELECT MAX(Test_id) FROM manufacture_data GROUP BY manufacture_name)

DEMO HERE

SELECT MANUFACTURE_NAME, MAX(TEST_ID) AS 'ID'
FROM TABLE T
GROUP BY MANUFACTURE_NAME
Select max(test_id) AS ID , manufacture_name from manufacture_data group by manufacture_name
select manufacture_data.* from manufacture_data
join (select Manufacture_Name, max(Test_id) as maxId from manufacture_data group by Manufacture_Name) as tmp 
on manufacture_data.Test_id = tmp.maxId

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM