Answer the question
In order to leave comments, you need to log in
How to select max value and return all row data?
Hello!
Guys, I'm breaking my head, I can't make a request to the database, I'm stupid even.
The discount table has 4 fields
id_skidki - int auto increment
company_id - int - ID of the company that provides the discount
percent_discount - tinyint - how much% discount is provided
end_date - DATETIME - until what date the discount is valid
The point is that I need to find the maximum discount for today and return the entire row with data, but it’s better to join it with the company table by company_id in order to pull out all the company data with one query so that there is no heavy load on the database.
I would be grateful for a hint, I'm sitting dumb (((
Answer the question
In order to leave comments, you need to log in
More or less like this:
SELECT * FROM discount
LEFT JOIN company ON discount.company_id=company.id
WHERE discount.end_date < CURDATE() + INTERVAL 1 DAY
ORDER BY percent_discount DESC
LIMIT 1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question