Friday, February 18, 2022

[FIXED] How to display the information of the customer who has the most 'use' in 'audit' table (Stored Procedure)

Issue

How to display the information of the customer who has the most 'use' in 'audit' table.

problem i dont know how to get information customer.

  select * from audit where used=
(select MAX(used) from audit)

audit table

enter image description here

customer table

enter image description here


Solution

Sort your subquery highest to lowest and then take the first row with LIMIT 1.


Select *
FROM customer_table
WHERE customer_ID = (
                     SELECT customer_ID
                     FROM audit_table
                     ORDER BY USED DESC
                     LIMIT 1
                     )

You may want to consider what happens if two customers have the same value in USED. It looks like there is a tie between C001 & C002 but this query will only return one customer



Answered By - urdearboy

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.