Japar S Japar S - 3 months ago 14
MySQL Question

Echo Record With MAX Value in Codeigniter

I want to echo record that has a MAX Value in php,So how i do that?

I have table like this:

id|value
1 | 3
2 | 1


What i've tried so far is use query
SELECT MAX(value) FROM user


but it just echo max user,so how i can show record with id that have MAX value in Codeigniter?

Answer

If you need only one row with actual data you should use another appoach with sorting and limit. See code below:

SELECT * FROM user order by value desc limit 1;