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 8561943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:37:08+00:00 2026-06-11T16:37:08+00:00

My table payment_status have these fields: id payment_id status created created_by Many entries could

  • 0

My table payment_status have these fields:

  • id
  • payment_id
  • status
  • created
  • created_by

Many entries could have the same payment_id… So, I want to get the last status for one payment_id…

I have this request that work but take too much time to load… I would like to have an optimize version to group by payment_id and take the last status.

SELECT pstatus.*
FROM `payment_status` AS pstatus
WHERE pstatus.id = (
   SELECT id
   FROM `payment_status`
   WHERE pstatus.status = '200'
   ORDER BY created DESC
   LIMIT 1
)
GROUP BY pstatus.payment_id
ORDER BY pstatus.payment_id DESC
  • 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-06-11T16:37:09+00:00Added an answer on June 11, 2026 at 4:37 pm

    Try this query –

    SELECT t1.* FROM payment_status t1
      JOIN (SELECT payment_id, MAX(created) max_created
            FROM payment_status
            GROUP BY payment_id
            ) t2
        ON t1.payment_id = t2.payment_id AND t1.created = t2.max_created;
    

    …then add WHERE conditions you need.

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

Sidebar

Related Questions

I have 3 table: [Order, Order_to_goods, Goods] I want to get of all participants
i have payment table fields update reason and amount & total field are change
I have two models that I would like to save in the same table.
Let say I have table Payments Id int autoincement Status int and my query
I have two tables as following table one named tbooking having column fields as
I have a table called payment which adds all the payment entries. I have
this is my invoice table: Invoice Table: invoice_id creation_date due_date payment_date status enum('not paid','paid','expired')
I have a payment_types table in which you can enter different payment types such
I have a MySQL table like this: Payments +----+---------------------+---------+ | id | date (sorted
I have a table that has multiple payments occuring on different dates each month.

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.