Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4107088
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:27:34+00:00 2026-05-20T21:27:34+00:00

I need to get certain tracked data, including a couple of max and mins.

  • 0

I need to get certain tracked data, including a couple of max and mins. I already have a horrible way to do it below, but as you know this is REALLY slow because i’m using subqueries and the table has a couple of thousands of rows. Specifically I need to get a different MAX values per row, depending on the type_dev of the current row. with 24000 records it becomes unusable, and I think is even slower when I try with MAX clauses instead.

SELECT dt.some_data, dt.date_visit, dt.url, 
      (SELECT date_visit FROM device_tracker 
       WHERE type_dev = dt.type_dev ORDER BY date_visit DESC LIMIT 1) last_visit,
      (SELECT date_visit FROM device_tracker 
       WHERE type_dev = dt.type_dev and url = dt.url ORDER BY date_visit DESC LIMIT 1) last_visit_to_this_url 
   FROM device_tracker dt WHERE some_where_clauses;

Please note that I don’t need global max values (it could be really easy), but for example in this case I’m getting the max date of every single type_dev (every row can be a different type or not) and also the max date of a certain url regarding each row.

I Need the same with the minimun dates.

For sure there are a lot of nicer ways to do it. Could anyone throw some light on it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T21:27:35+00:00Added an answer on May 20, 2026 at 9:27 pm
    SELECT  *
    FROM    (
            SELECT  type_dev, MAX(date_visit) AS maxt, MIN(date_visit) AS mint
            FROM    device_tracker
            GROUP BY
                    type_dev
            ) t
    JOIN    (
            SELECT  type_dev, url, MAX(date_visit) AS maxtu, MIN(date_visit) AS mintu
            FROM    device_tracker
            GROUP BY
                    type_dev, url
            ) tu
    ON      tu.type_dev = t.type_dev
    JOIN    device_tracker dt
    ON      dt.type_dev = tu.type_dev
            AND dt.url = tu.url
    

    Create a composite index on (type_dev, url, date_visit) for this to work fast.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need your help to get the max of CAP_PRICE based on certain criteria in
I have a table with 40 (int) columns and I need to get certain
I have a large amount of log data that I need to get some
Need to get a certain subgroup of data per day (Separated by weekday) For
I have a stored procedure which deletes certain records. I need to get the
I'm not a c# programmer at all, but need to get certain calculations from
I need to figure out a way to get certain column's of my jquery's
I have used the line below in my app. But now I need to
I need to get the Handler to the child Window of a certain application
I need get all items these have no categories int? categoryId = null; var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.