MySQL Forums :: Performance :: Query with 2 x subquery


Advanced Search

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
Query with 2 x subquery 732 Jes Ramsing 04/29/2016 06:44AM
Re: Query with 2 x subquery 411 Øystein Grøvlen 04/29/2016 08:01AM
Re: Query with 2 x subquery 388 Jes Ramsing 05/01/2016 11:57PM
Re: Query with 2 x subquery 344 Øystein Grøvlen 05/02/2016 03:45AM
Re: Query with 2 x subquery 355 Jes Ramsing 05/02/2016 05:32AM
Re: Query with 2 x subquery 357 Rick James 05/01/2016 11:58PM
Re: Query with 2 x subquery 401 Jes Ramsing 05/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.