---
title: "Select the maximum value of a colum in MySQL"  
description: "Select the maximum value of a colum in MySQL"  
author: "Anonymous User"  
published: 2015-12-01  
updated: 2015-12-01  
canonical: https://www.mindstick.com/forum/33667/select-the-maximum-value-of-a-colum-in-mysql  
category: "mysql"  
tags: ["database", "php", "mysql"]  
reading_time: 1 minute  

---

# Select the maximum value of a colum in MySQL

All I want to do is [select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) the [maximum value](https://www.mindstick.com/forum/158769/implement-a-function-to-find-the-maximum-value-in-a-list-of-numbers-in-python) of a [column](https://www.mindstick.com/forum/33860/how-to-calculate-column-summary-in-sql-server) in MySQL. Like this:

```
$max = "SELECT MAX(Id) FROM trialtabel2"; $max1 =  mysqli_query($dblink, $max); echo= $max1;
```

My [debugger](https://www.mindstick.com/forum/2141/how-to-debug-a-vb-dot-net-webmethod) is just saying that it is a [query](https://www.mindstick.com/blog/202/sub-query-in-sqlserver) [returning](https://www.mindstick.com/news/2477/returning-ceo-bob-iger-dismisses-the-disney-apple-sale-as-pure-speculation) a 0 [boolean](https://www.mindstick.com/forum/160332/how-does-the-boolean-function-work) value (false)

## Replies

### Reply by Anonymous User

We need to fetch the data from the mysqli_result object that was returned to you when you executed your query using mysqli_query.

```
    $max = "SELECT MAX(Id) as id FROM trialtabel2";     $max1 =  mysqli_query($dblink, $max);     $row = mysqli_fetch_assoc($max1);    // this was missing    $id=$row['id'];    echo $id;
```

Note: I removed the loop because with MAX query without any grouping you will get only 1 row returned. If you had multiple rows in result set you would need to loop through all of them


---

Original Source: https://www.mindstick.com/forum/33667/select-the-maximum-value-of-a-colum-in-mysql

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
