mysql - Get rid of slow subquery -


I have a database of connection to my server, currently with 2,300,000 lines.

I run the following query to find a connection by a user, remove duplicates, if nick / ip / client_id are the same. 'IP', hex (`` `` `` `` `` `` `` `` `` `` `` `` `` `` " Also, in the form of 'Nick' 'as' Customer_ID 'as' Customer_ID`, UNIX_TIMESTAMP (`date`) from 'date' (selection 'from' to 'date' DESC) also things like this: - 'IP' & INET_ATON ('255.255.0.0') = INET_ATON ('123.123.0.0') by the group `nick`,` ip`, `customer_id` by` date` orders by dsc limit 500 < / Pre>

Why do I use a subquery in the first place? Use the GROUP BY To get the latest date value while doing this

I think the query ORDER BY The role of and GROUP BY is misunderstood to get the latest date nick, ip, client_id , you will type the query as follows:

 SELECT `nick`, INET_NTOA (` ip`) In the form of `IP`, hex (` customer_id`) as' client_id`, maximum (UNIX_TIMESTAMP (`date`))` from date` `` when Like 'nick' as '% nick'% - also ace Only things can be done: - 'IP' and INET_ATON ('255.255.0.0') = INET_ATON ('123.123.0.0') Order by the group 'nick', `ip`,` customer_id`, up to the DESC limit 500 

There is no need for a subquery at all. This code gives data to the group and then

 UNIX_TIMESTAMP (`dated`) 

Returns the maximum value of date .


Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -