MySQL Forums
Forum List  »  Performance

Re: Query with 2 x subquery
Posted by: Rick James
Date: May 01, 2016 11:58PM

I'm not clear on what you are doing, but maybe this:
    SELECT  c1.varid, c1.val, c1.sessionid
        FROM  data_i16 AS c1
        JOIN  
          ( SELECT  varid, MAX(sessionid) AS sessionid
                FROM  data_i16
                WHERE partid = '5'
                  AND sessionid < 1611659
                GROUP BY  varid
          ) AS c2 USING (varid, sessionid)
        WHERE partid = '5'
          AND sessionid < 1611659
        ORDER BY  c1.sessionid DESC;

data_i16 will need INDEX(varid, sessionid) and INDEX(partid, sessionid).

That's "groupwise max" with an added restraing of WHERE partid = '5' AND sessionid < 1611659

http://mysql.rjweb.org/doc.php/groupwise_max

Options: ReplyQuote


Subject
Views
Written By
Posted
777
April 29, 2016 06:44AM
428
April 29, 2016 08:01AM
406
May 01, 2016 11:57PM
374
May 02, 2016 05:32AM
Re: Query with 2 x subquery
382
May 01, 2016 11:58PM
421
May 02, 2016 02:16AM


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.