Answer the question
In order to leave comments, you need to log in
What is the correct way to write SELECT with MAX()?
Hello. I have a table
One "site" can have several "receipts". I am writing a query in which I want to get the record with the highest receipt number for a particular parcel. I am using mysql driver for nodeJS
case('getReceiptNumber'):
debug.ok('Запрос номера квитанции');
var values = [
receipt',
'number',
'number',
'receipt',
'rpu',
frontReq.data //тут номер участка, например 100
];
databaseReal("SELECT * FROM ?? WHERE ?? = (SELECT MAX(??) FROM ??) AND ?? = ?", values, function(req){
ajaxResponse = req;
res.end(JSON.stringify(ajaxResponse));
debug.ok(req);
});
break;
Answer the question
In order to leave comments, you need to log in
Thank you all, thanks to you made:
SELECT * FROM 'таблица'
WHERE 'номер участка' = '100'
ORDER BY 'номер квитанции' DESC
LIMIT 1
SELECT `Номер участка`, COUNT(*) AS `count`
FROM `table`
ORDER BY `count` DESC
LIMIT 1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question