i am trying to execute the distinct records from mysql table having max value of it sno column. I have tried the following query but having no luck.
SELECT DISTINCT p.sno AS sno, p.short_order,p.fir_sno
FROM pre_trials p, fir f
WHERE p.fir_sno = f.sno
GROUP BY p.fir_sno
ORDER BY p.sno ASC
For the above query i have the following table:
It should return sno 4,5 because both having the maximum value of sno column. I don't know how to retrieve the record according to my requirements? Any help will be appreciated. thanks
EDIT: Show Create Table fir,pre_trials


fir_sno? – Derek Downey Jan 19 '16 at 15:17fir_sno(values 1,2), you want the 'latest' row (max(date))? Hence you want 2 rows: ids 4,5? That is what "groupwise max" is s about -- group byfir_sno, but deliver the last (max date) row for for each. – Rick James Jan 20 '16 at 20:59fir_sno, according to your sample data, cannot be thePRIMARY KEY, at least not by itself. The sample data show multiples rows for the same value offir_sno.Please provideSHOW CREATE TABLE`. – Rick James Jan 22 '16 at 01:08CREATE TABLEstatements as text, not as screenshots. – ypercubeᵀᴹ Jan 22 '16 at 17:53