user2375298
user2375298

Reputation: 1041

explain the sub query working MySQL

Writing a query to display the book code, book title ,supplier name and price of the book which takes maximum price based on each supplier.

I found the below query getting me right result but need explanations

select a.book_code,c.supplier_name,a.price from lms_book_details a 
  where a.price= (select max(price) from lms_book_details 
                   where supplier_id= a.supplier_id )
                  order by book_code;
  order by book_code;

Upvotes: 0

Views: 51

Answers (1)

Prahalad Gaggar
Prahalad Gaggar

Reputation: 11599

Your query will fetch the row from lms_book_details with maximum price. If there more than one Row (record) with maximum price then it will return more than 1 and then order by book_code

Upvotes: 1

Related Questions