mysql - How to translate this sql to left join without subquery? -


i want create view in mysql.but in mysql does't support subquery. how write sql without subquery?

select * dev_location t1          inner join       (         select             `dev_location`.`device_id` `device_id`,             max(`dev_location`.`id`) `id`                     `dev_location`         group `dev_location`.`device_id`) t2      on t1.id = t2.id 

mysql views don't support subqueries in from clause. following should work in view:

select dl.* dev_location dl not exists (select 1                   dev_location dl2                   dl2.device_id = dl.device_id ,                         dl2.id > dl.id                  ); 

this reformulates query say: "get me rows dev_location device_id has no greater id." awkward way of getting max.

and, index on dev_location(device_id, id), might perform better version.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -