arunangaj
arunangaj

Reputation: 1

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

enter image description here 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?

Upvotes: 0

Views: 65

Answers (5)

Hắc Huyền Minh
Hắc Huyền Minh

Reputation: 1035

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

Upvotes: 0

Bipul Khan
Bipul Khan

Reputation: 707

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

Upvotes: 2

echo_Me
echo_Me

Reputation: 37233

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

Upvotes: 0

Macrosoft-Dev
Macrosoft-Dev

Reputation: 2185

Select max(test_id) AS ID , manufacture_name from manufacture_data group by manufacture_name

Upvotes: 0

DNac
DNac

Reputation: 2783

SELECT MANUFACTURE_NAME, MAX(TEST_ID) AS 'ID'
FROM TABLE T
GROUP BY MANUFACTURE_NAME

Upvotes: 0

Related Questions