<?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>LAST_INSERT_ID &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/last_insert_id/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>Tue, 19 Sep 2017 07:29:09 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>MySQL: Get ID of the Last Updated Row</title>
		<link>https://www.dbrnd.com/2015/11/mysql-get-id-of-the-last-updated-row/</link>
					<comments>https://www.dbrnd.com/2015/11/mysql-get-id-of-the-last-updated-row/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 01 Nov 2015 18:44:59 +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[LAST_INSERT_ID]]></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=993</guid>

					<description><![CDATA[In this post, I am sharing a demonstration on how to get last updated ID of the last updated row in MySQL. Many times, we require updating the data basis on last updated table id. We should write update query such a way that we can get a last updated ID in the update statement [&#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%2F2015%2F11%2Fmysql-get-id-of-the-last-updated-row%2F&amp;linkname=MySQL%3A%20Get%20ID%20of%20the%20Last%20Updated%20Row" 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%2F2015%2F11%2Fmysql-get-id-of-the-last-updated-row%2F&amp;linkname=MySQL%3A%20Get%20ID%20of%20the%20Last%20Updated%20Row" 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%2F2015%2F11%2Fmysql-get-id-of-the-last-updated-row%2F&amp;linkname=MySQL%3A%20Get%20ID%20of%20the%20Last%20Updated%20Row" 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%2F2015%2F11%2Fmysql-get-id-of-the-last-updated-row%2F&amp;linkname=MySQL%3A%20Get%20ID%20of%20the%20Last%20Updated%20Row" 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%2F2015%2F11%2Fmysql-get-id-of-the-last-updated-row%2F&amp;linkname=MySQL%3A%20Get%20ID%20of%20the%20Last%20Updated%20Row" 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%2F2015%2F11%2Fmysql-get-id-of-the-last-updated-row%2F&amp;linkname=MySQL%3A%20Get%20ID%20of%20the%20Last%20Updated%20Row" 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%2F2015%2F11%2Fmysql-get-id-of-the-last-updated-row%2F&#038;title=MySQL%3A%20Get%20ID%20of%20the%20Last%20Updated%20Row" data-a2a-url="https://www.dbrnd.com/2015/11/mysql-get-id-of-the-last-updated-row/" data-a2a-title="MySQL: Get ID of the Last Updated Row"></a></p><p>In this post, I am sharing a demonstration on how to get last updated ID of the last updated row in MySQL.</p>
<p>Many times, we require updating the data basis on last updated table id.</p>
<p>We should write update query such a way that we can get a last updated ID in the update statement only. </p>
<p>Here, I am sharing different ways for getting a last updated ID of the last updated row.</p>
<p><strong>Let&#8217;s first create a table with sample data. </strong><br />
<pre class="crayon-plain-tag">CREATE TABLE tbl_LastUpdateID
(
    Rno INTEGER AUTO_INCREMENT 
    ,Name VARCHAR(50)
    ,CONSTRAINT pk_tbl_LastUpdateID_Rno PRIMARY KEY(Rno)
);

INSERT INTO tbl_LastUpdateID (Name) VALUES ('Anvesh');
INSERT INTO tbl_LastUpdateID (Name) VALUES ('Neevan');
INSERT INTO tbl_LastUpdateID (Name) VALUES ('Roy');</pre>
<p><strong>First script to get a last updated ID:</strong><br />
<pre class="crayon-plain-tag">SET @LastUpdateID := 0;
UPDATE tbl_LastUpdateID 
	SET Name = 'Alex',Rno = (SELECT @LastUpdateID := Rno)
WHERE Name = 'Roy';
SELECT @LastUpdateID AS LastUpdateID;</pre>
<p><strong>Get all last updated ID when more than one row updates:</strong><br />
<pre class="crayon-plain-tag">SET @LastUpdateID := NULL;
UPDATE tbl_LastUpdateID
   SET Name = 'All'
WHERE Name &lt;&gt;'All'
AND (SELECT @LastUpdateID := CONCAT_WS(',', Rno, @LastUpdateID));
SELECT @LastUpdateID;</pre>
<p><strong>Second script using LAST_INSERT_ID():</strong><br />
Before this, please execute the insert script again.<br />
<pre class="crayon-plain-tag">UPDATE tbl_LastUpdateID
SET Name = 'Martin'
    ,Rno=LAST_INSERT_ID(Rno)
WHERE Name = 'Roy';
SELECT LAST_INSERT_ID();</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2015/11/mysql-get-id-of-the-last-updated-row/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
