<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>max value &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/max-value/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Sun, 02 Oct 2016 18:14:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>MySQL: How to get Max Value for each group?</title>
		<link>https://www.dbrnd.com/2016/10/mysql-how-to-get-max-value-for-each-group/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 01 Oct 2016 16:16:47 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[group by]]></category>
		<category><![CDATA[max value]]></category>
		<category><![CDATA[MySQL Command]]></category>
		<category><![CDATA[MySQL Database Administrator]]></category>
		<category><![CDATA[MySQL Database Designing]]></category>
		<category><![CDATA[MySQL Database Programming]]></category>
		<category><![CDATA[MySQL Error]]></category>
		<category><![CDATA[MySQL Performance Tunning]]></category>
		<category><![CDATA[MySQL Query]]></category>
		<category><![CDATA[MySQL Tips and Tricks]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=2126</guid>

					<description><![CDATA[In this post, I am giving you a full demonstration on finding max value for each group of records in MySQL. Today morning, I was working on one report and requirement is to find max value records for each particular group of data. I know, You guys are thinking that this is a very simple [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-how-to-get-max-value-for-each-group%2F&amp;linkname=MySQL%3A%20How%20to%20get%20Max%20Value%20for%20each%20group%3F" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-how-to-get-max-value-for-each-group%2F&amp;linkname=MySQL%3A%20How%20to%20get%20Max%20Value%20for%20each%20group%3F" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-how-to-get-max-value-for-each-group%2F&amp;linkname=MySQL%3A%20How%20to%20get%20Max%20Value%20for%20each%20group%3F" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-how-to-get-max-value-for-each-group%2F&amp;linkname=MySQL%3A%20How%20to%20get%20Max%20Value%20for%20each%20group%3F" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-how-to-get-max-value-for-each-group%2F&amp;linkname=MySQL%3A%20How%20to%20get%20Max%20Value%20for%20each%20group%3F" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-how-to-get-max-value-for-each-group%2F&amp;linkname=MySQL%3A%20How%20to%20get%20Max%20Value%20for%20each%20group%3F" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-how-to-get-max-value-for-each-group%2F&#038;title=MySQL%3A%20How%20to%20get%20Max%20Value%20for%20each%20group%3F" data-a2a-url="https://www.dbrnd.com/2016/10/mysql-how-to-get-max-value-for-each-group/" data-a2a-title="MySQL: How to get Max Value for each group?"></a></p><p>In this post, I am giving you a full demonstration on finding max value for each group of records in MySQL.</p>
<p>Today morning, I was working on one report and requirement is to find max value records for each particular group of data.</p>
<blockquote><p>I know, You guys are thinking that this is a very simple solution using MAX() and GROUP BY clause.<br />
<strong>But many of database developers have always questioned about:</strong> Why we cannot add any other columns in SELECT list which are not part of aggregation or the GROUP BY clause?</p></blockquote>
<p>Below is a one solution, you can find MAX record without using GROUP BY clause and you can also add other columns in the SELECT list. </p>
<p><strong>First, Create a table with sample data:</strong></p><pre class="crayon-plain-tag">CREATE TABLE tbl_EmployeeDetails
(
	EmpID INTEGER PRIMARY KEY 
    ,EmpName VARCHAR(50)
    ,EmpSalary BIGINT
    ,DepartmentName VARCHAR(50)
);

INSERT INTO tbl_EmployeeDetails
VALUES 
(1,'Anvesh',80000,'Sales')
,(2,'Neevan',90000,'Sales')
,(3,'Jenny',50000,'Production')
,(4,'Roy',60000,'Production')
,(5,'Martin',30000,'Research')
,(6,'Mahi',85000,'Research')
,(7,'Kruti',45000,'Research')
,(8,'Manish',75000,'Research');</pre><p>
<strong>Find max salary values for each department:</strong></p><pre class="crayon-plain-tag">SELECT ED1.*
FROM tbl_EmployeeDetails ED1                   
LEFT JOIN tbl_EmployeeDetails ED2       
  ON ED1.DepartmentName = ED2.DepartmentName 
  AND ED1.EmpSalary &lt; ED2.EmpSalary
WHERE ED2.EmpSalary IS NULL</pre><p>
<strong>The Result:</strong></p>
<p><a href="https://www.dbrnd.com/wp-content/uploads/2016/03/MySQLMaxValueForEachGroup.png" rel="attachment wp-att-2128"><img decoding="async" class="alignnone wp-image-2128 size-full" title="MySQL Max Value For Each Group" src="https://www.dbrnd.com/wp-content/uploads/2016/03/MySQLMaxValueForEachGroup.png" alt="MySQL Max Value For Each Group" width="285" height="94" srcset="https://www.dbrnd.com/wp-content/uploads/2016/03/MySQLMaxValueForEachGroup.png 285w, https://www.dbrnd.com/wp-content/uploads/2016/03/MySQLMaxValueForEachGroup-150x49.png 150w" sizes="(max-width: 285px) 100vw, 285px" /></a></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
