Answer the question
In order to leave comments, you need to log in
Why are max() results not correct (mysql)?
There is a table with fields
meta_id, post_id, meta_key, meta_value Meta_value
values are:
5247
5205
4028
3176
2123
2119
2119
2006
12800
12424
and so on... up to 70000
you need to display the largest of the range between 1000 and 30000.
I create a query
SELECT
max(meta_value)
FROM
postmeta
WHERE
meta_key = 'property_id'
AND meta_value BETWEEN 1000 AND 30000;
Answer the question
In order to leave comments, you need to log in
As a result, in order to sort such a table, I googled and applied such a hack
(meta_value * 1) <-- this converts the string 12345 into a number, and sorting works correctly.
SELECT distinct
meta_value
FROM
postmeta
WHERE
meta_key = 'property_id'
AND meta_value BETWEEN 1000 AND 30000
ORDER BY (meta_value * 1) DESC;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question