php - using group by and order by in mysql query correctly -


i'm trying latest certificate user has database. want see latest 1 , not others i'm using group , ordering unique id main table.

without group works perfectly. see last certificate uploaded , others below.

as add group see first certificate ever uploaded pointless years ago.

my query quite large i'm drawing in lot of other information other tables.

here query.

    select          usercert.*,          cert.*,         certcat.certcatname,         certtask.certtaskname ,         certstatus.certstatusname               `usercert`     inner join          cert      on          cert.idcert = usercert.idcert     inner join          certcat      on          certcat.idcertcat = cert.idcertcat     inner join          certtask      on          certtask.idcerttask = usercert.idcerttask     inner join           certstatus      on          certstatus.idcertstatus =   usercert.idcertstatus               usercert.iduser=%s      group          usercert.idcert       order          usercert.usercertend desc 

select      usercert.*,      cert.*,     certcat.certcatname,     certtask.certtaskname ,     certstatus.certstatusname       `usercert` inner join      cert  on      cert.idcert = usercert.idcert inner join      certcat  on      certcat.idcertcat = cert.idcertcat inner join      certtask  on      certtask.idcerttask = usercert.idcerttask inner join      certstatus  on      certstatus.idcertstatus = usercert.idcertsttus       usercert.iduser=%s  order      usercert.usercertend  desc limit 0,1 

in query take record in descending order means last inserted row come first , limit 0,1 means start 0 , fetch 1 record that's ...


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -