mysql - SQL If records are repetitive select the one with the max id -
i have query returns older versions of records (due bad database design) , try newest ones. try ones max id's query complicated , there lots of records. subselect queries wont work:
select row table id=( select max(id) table ) and here's query. way company using testlink, if you're familiar , have better solution this, appreciated.
select req_doc_id, scope,nh.parent_id,nh.id (select nh.id, req_doc_id,doc_id nodes_hierarchy nh, req_specs r1, requirements r2 nh.parent_id = r1.id , nh.id = r2.id , (r1.doc_id '%blabla%' or r1.doc_id '%tralala%')) t1, nodes_hierarchy nh, req_versions r1 t1.id = nh.parent_id , nh.id = r1.id and resultset is
name..................id ____ blabla1..............163 blabla1..............190 blabla2..............173 tralala..............15 tralala2.............26 tralala2.............19 what want is:
name..................id ____ blabla1..............190 blabla2..............173 tralala..............15 tralala2.............26
select tb.name,tb.id table tb inner join ( select name,max(id) id table group name )innertable on innertable.id=tb.id try above query.
hope you.
Comments
Post a Comment