---
title: "Select cell from same column with MAX function in mySql"  
description: "Select cell from same column with MAX function in mySql"  
author: "Anonymous User"  
published: 2013-07-17  
updated: 2013-07-17  
canonical: https://www.mindstick.com/forum/1298/select-cell-from-same-column-with-max-function-in-mysql  
category: "mssql server"  
tags: ["mssql server"]  
reading_time: 1 minute  

---

# Select cell from same column with MAX function in mySql

HI [developers](https://www.mindstick.com/articles/12875/blunders-you-must-avoid-while-hiring-java-developers-to-get-the-best-fulfilling-your-needs)!

[Table](https://www.mindstick.com/articles/43918/how-to-design-table-using-bootstrap) for example:

event_id| group_id | updated_at

1 | 1 |2012-01-02

2 | 1 |2012-01-01

3 | 2 |2012-01-01

4 | 2 |2012-01-02

5 | 3 |2012-01-01

I need [select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) all event_id with [max](https://www.mindstick.com/articles/1155/count-max-min-function-in-excel) [date](https://yourviews.mindstick.com/story/3869/propose-day-2024-exciting-date-ideas-for-you-and-your-partner), grouped by group_id. So [right](https://www.mindstick.com/articles/12766/check-whether-you-are-doing-digital-transformation-right-or-not) [result](https://www.mindstick.com/blog/12011/advantages-of-getting-result-oriented-seo-from-an-agency) will be:

event_id| group_id | updated_at

1 | 1 |2012-01-02

4 | 2 |2012-01-02

5 | 3 |2012-01-01

Can I select event_id, from the same [row](https://www.mindstick.com/forum/1212/this-row-already-belongs-to-this-table) that MAX(updated_at) has been selected?

SELECT event_id, group_id, MAX(updated_at)

FROM my_table

[GROUP](https://yourviews.mindstick.com/view/81323/adani-green-energy-group-bags-world-s-biggest-solar-bid) BY group_id;

Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)

## Replies

### Reply by shreesh chandra shukla

Solution!

MySQL may allow the type of syntax you suggest - specifying non-aggregate columns that are also not part of the group by - but it is non-standard and IMHO a bad habit to get into.

Instead, you would do:

SELECT t1.event_id, t1.group_id, t1.updated_at

FROM my_table t1

INNER JOIN

(

SELECT group_id, MAX(updated_at) AS max_updated_at

FROM my_table

GROUP BY group_id

) t2 ON t1.group_id = t2.group_id AND t1.updated_at = t2.max_updated_at

Note though if updated_at is non-unique for a given group_id, this query will return all of said rows.


---

Original Source: https://www.mindstick.com/forum/1298/select-cell-from-same-column-with-max-function-in-mysql

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
