skip to Main Content

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

2

Answers


  1. 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

    Login or Signup to reply.
  2. This will select the first record from the result set ordered by used in descending order.

    Select TOP 1 *
    from audit
    order by used desc
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search