I have created a table Books with the following attributes: Books(BookID, BookName, Author, Price)
Now I wish to find the name of the book which has the least price(cheapest book's name), along with its price.
To do so, I did something like:
SELECT min(Price) FROM Books;
This gave me the minimum price ($55.36). And then I used:
SELECT BookName,Price FROM Books
WHERE Price=55.36;
This gave me the answer I was looking for...
But I want to ask, is there a better way, so that I don't need to know the minimum price before finding the answer?Can I do it in a single query?
I tried something like:
SELECT BookName,Price FROM Books
WHERE Price=min(Price);
But I got an Invalid use of Group function error. Any help would be appreciated. I am using MySQL Server version 8.0.
Thanks!