MySQL Forums
Forum List  »  InnoDB

Re: why must i specify an index in query?
Posted by: Peter Brawley
Date: July 02, 2015 10:36PM

> The purpose of the query is to pull all the users and join their last page accessed.

If that's correct, the Left Join is senseless since obviously, if the user has any userhits rows, she has a last one, so the query would be ...

select u.*, t.id  
from usersmobile u
join (
  select userid2, max(id) as lastID
  from userhits
  group by userid2
) t on u.id=t.userid2;

and you can if desired add a second join to userhits to get detail userhits cols ....

join userhits d on t.lastID=d.id

Or do you mean: pull all the users and join their last page accessed if any? In that case, you're stuck wit the left join.

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: why must i specify an index in query?
908
July 02, 2015 10:36PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.