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

  • Home
  • SEARCH
  • 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 6961945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:35:47+00:00 2026-05-27T15:35:47+00:00

I have two tables – one called customer_records and another called customer_actions . customer_records

  • 0

I have two tables – one called customer_records and another called customer_actions.

customer_records has the following schema:

CustomerID (auto increment, primary key)
CustomerName
...etc...

customer_actions has the following schema:

ActionID (auto increment, primary key)
CustomerID (relates to customer_records)
ActionType
ActionTime (UNIX time stamp that the entry was made)
Note (TEXT type)

Every time a user carries out an action on a customer record, an entry is made in customer_actions, and the user is given the opportunity to enter a note. ActionType can be one of a few values (like ‘designatory update’ or ‘added case info’ – can only be one of a list of options).

What I want to be able to do is display a list of records from customer_records where the last ActionType was a certain value.

So far, I’ve searched the net/SO and come up with this monster:

SELECT * FROM (
    SELECT * FROM (
        SELECT * FROM `customer_actions` ORDER BY `EntryID` DESC
    ) list1 GROUP BY `CustomerID`
) list2 WHERE `ActionType`='whatever' LIMIT 0,30

Which is great – it lists each customer ID and their last action. But the query is extremely slow on occasions (note: there are nearly 20,000 records in customer_records). Can anyone offer any tips on how I can sort this monster of a query out or adjust my table to give faster results? I’m using MySQL. Any help is really appreciated, thanks.

Edit: To be clear, I need to see a list of customers who’s last action was ‘whatever’.

  • 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-27T15:35:48+00:00Added an answer on May 27, 2026 at 3:35 pm

    To filter customers by their last action, you could use a correlated sub-query…

    SELECT
      *
    FROM
      customer_records
    INNER JOIN
      customer_actions
        ON  customer_actions.CustomerID = customer_records.CustomerID
        AND customer_actions.ActionDate = (
               SELECT
                 MAX(ActionDate)
               FROM
                 customer_actions  AS lookup
               WHERE
                 CustomerID = customer_records.CustomerID
            )
    WHERE
      customer_actions.ActionType = 'Whatever'
    

    You may find it more efficient to avoid the correlated sub-query as follows…

    SELECT
      *
    FROM
      customer_records
    INNER JOIN
      (SELECT CustomerID, MAX(ActionDate) AS ActionDate FROM customer_actions GROUP BY CustomerID) AS last_action
        ON customer_records.CustomerID = last_action.CustomerID
    INNER JOIN
      customer_actions 
        ON  customer_actions.CustomerID = last_action.CustomerID
        AND customer_actions.ActionDate = last_action.ActionDate
    WHERE
      customer_actions.ActionType = 'Whatever'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables: one called Projects, and another called Documents (projects has many
I have two tables. One of events and one of articles. Each event has
I have two tables that are joined together. A has many B Normally you
I have two tables in my database, called ratings and movies . Ratings: |
I have two tables, one that contains volunteers, and one that contains venues. Volunteers
I have two tables A & B, and B has a many:1 relationship with
I have two tables, one parent Point and one child PointValue, connected by a
I have two tables that I want to join into one table and use
I have two tables: A (col1,col2,col3,col4) B (col1,col2,col3,col4) Table A has 4 records(rows) and
I have two tables, items and itemmeta. items has item_id which links it to

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.