<?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>tanhaaiyaaN &#187; mysql</title>
	<atom:link href="http://www.tanhaa.net/index.php/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tanhaa.net</link>
	<description>Notes from the underground!</description>
	<lastBuildDate>Tue, 01 Nov 2011 17:01:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>mysql &#8211; identifying number of duplicates in a table</title>
		<link>http://www.tanhaa.net/index.php/2007/08/16/mysql-identifying-number-of-duplicates-in-a-table/</link>
		<comments>http://www.tanhaa.net/index.php/2007/08/16/mysql-identifying-number-of-duplicates-in-a-table/#comments</comments>
		<pubDate>Thu, 16 Aug 2007 22:17:18 +0000</pubDate>
		<dc:creator>tanhaa</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.tanhaa.net/index.php/2007/08/16/mysql-identifying-number-of-duplicates-in-a-table/</guid>
		<description><![CDATA[So my little query adventures with mySQL continues. Here&#8217;s another unique problem: There are duplicates in the table as there is no field that was setup as primary index. So how do we know how many do we have? Well assume that the duplicate values happen on the &#8220;Phone Number&#8221; of the client. Here&#8217;s the [...]]]></description>
			<content:encoded><![CDATA[<p>So my little query adventures with mySQL continues.  Here&#8217;s another unique problem:  There are duplicates in the table as there is no field that was setup as primary index.  So how do we know how many do we have?</p>
<p>Well assume that the duplicate values happen on the &#8220;Phone Number&#8221; of the client.  Here&#8217;s the query you would run:<br />
select `BUSINESS PHONE`, count(*) as &#8216;Num of Dups&#8217;<br />
from mytable<br />
group by `BUSINESS PHONE`<br />
having count(*) > 1</p>
<table id="table_results" class="data">
<thead>
<th></th>
<th></th>
</thead>
</table>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.tanhaa.net%2Findex.php%2F2007%2F08%2F16%2Fmysql-identifying-number-of-duplicates-in-a-table%2F&amp;title=mysql%20%26%238211%3B%20identifying%20number%20of%20duplicates%20in%20a%20table" id="wpa2a_2"><img src="http://www.tanhaa.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.tanhaa.net/index.php/2007/08/16/mysql-identifying-number-of-duplicates-in-a-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mysql &#8211; Appending data</title>
		<link>http://www.tanhaa.net/index.php/2007/07/10/mysql-appending-data/</link>
		<comments>http://www.tanhaa.net/index.php/2007/07/10/mysql-appending-data/#comments</comments>
		<pubDate>Tue, 10 Jul 2007 20:40:30 +0000</pubDate>
		<dc:creator>tanhaa</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[techno-babble]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.tanhaa.net/index.php/2007/07/10/mysql-appending-data/</guid>
		<description><![CDATA[Problem: Appending data from one table to another table where duplicate might exist. Solution: A simple &#8220;Insert into table2 select * from table1&#8243; query will give errors saying &#8220;duplicate records exist&#8221;, to go around it, the following query should do the job: INSERT INTO MASTERTABLE SELECT * FROM NEWTABLE WHERE NEWTABLE.`UNIQUEID` NOT IN (SELECT `UNIQUEID` [...]]]></description>
			<content:encoded><![CDATA[<p>Problem:<br />
Appending data from one table to another table where duplicate might exist.<br />
Solution:<br />
A simple &#8220;Insert into table2 select * from table1&#8243; query will give errors saying &#8220;duplicate records exist&#8221;, to go around it, the following query should do the job:</p>
<p><span class="syntax_alpha syntax_alpha_reservedWord" /><br />
<span class="syntax"><span class="syntax_alpha syntax_alpha_reservedWord">INSERT</span>  <span class="syntax_alpha syntax_alpha_reservedWord">INTO</span> <span class="syntax_alpha syntax_alpha_identifier">MASTERTABLE</span><br />
<span class="syntax_alpha syntax_alpha_reservedWord">SELECT</span>  <span class="syntax_punct">*</span><br />
<span class="syntax_alpha syntax_alpha_reservedWord">FROM</span> <span class="syntax_alpha syntax_alpha_identifier">NEWTABLE</span><br />
<span class="syntax_alpha syntax_alpha_reservedWord">WHERE</span> <span class="syntax_alpha syntax_alpha_identifier">NEWTABLE</span><span class="syntax_punct syntax_punct_qualifier">.</span><span class="syntax_quote syntax_quote_backtick">`UNIQUEID`</span>  <span class="syntax_alpha syntax_alpha_reservedWord">NOT</span><br />
<span class="syntax_alpha syntax_alpha_reservedWord">IN</span> <span class="syntax_punct syntax_punct_bracket_open_round">(</span></span><span class="syntax_alpha syntax_alpha_reservedWord">SELECT</span>  <span class="syntax_quote syntax_quote_backtick">`UNIQUEID`</span> <span class="syntax"><span class="syntax_punct syntax_punct_bracket_open_round"></span></p>
<div class="syntax_indent1"><span class="syntax_alpha syntax_alpha_reservedWord">FROM</span> <span class="syntax_alpha syntax_alpha_identifier">MASTERTABLE</span></div>
<p><span class="syntax_punct syntax_punct_bracket_close_round">)</span></span></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.tanhaa.net%2Findex.php%2F2007%2F07%2F10%2Fmysql-appending-data%2F&amp;title=Mysql%20%26%238211%3B%20Appending%20data" id="wpa2a_4"><img src="http://www.tanhaa.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.tanhaa.net/index.php/2007/07/10/mysql-appending-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL non-matching Records</title>
		<link>http://www.tanhaa.net/index.php/2007/06/15/mysql-non-matching-records/</link>
		<comments>http://www.tanhaa.net/index.php/2007/06/15/mysql-non-matching-records/#comments</comments>
		<pubDate>Fri, 15 Jun 2007 18:40:05 +0000</pubDate>
		<dc:creator>tanhaa</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[techno-babble]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.tanhaa.net/index.php/2007/06/15/mysql-non-matching-records/</guid>
		<description><![CDATA[Problem: Finding records in Table b that do not match records in Table a This sort of problem may arise when you need to scrub a file against another or run a duplicate scan on a file against another to weed out any duplicates that may exist prior to doing whatever it is you need [...]]]></description>
			<content:encoded><![CDATA[<p>Problem:  Finding records in Table b that do not match records in Table a</p>
<p>This sort of problem may arise when you need to scrub a file against another or run a duplicate scan on a file against another to weed out any duplicates that may exist prior to doing whatever it is you need to do with that file.  Lets assume that both the tables have a field called &#8220;PHONE&#8221; that identifies your clients as unique.<br />
The query that you will need to run uses LEFT JOIN function</p>
<p><span class="syntax"><span class="syntax_alpha syntax_alpha_reservedWord">SELECT</span>  <span class="syntax_punct">*</span> <span class="syntax_alpha syntax_alpha_reservedWord">FROM</span> <span class="syntax_alpha syntax_alpha_identifier" /><span class="syntax_alpha syntax_alpha_identifier" /><span class="syntax_white syntax_white_newline" />TableB b<br />
<span class="syntax_alpha syntax_alpha_reservedWord">LEFT</span>  <span class="syntax_alpha syntax_alpha_reservedWord">OUTER</span>  <span class="syntax_alpha syntax_alpha_reservedWord">JOIN</span> <span class="syntax_alpha syntax_alpha_identifier">TableA</span> <span class="syntax_alpha syntax_alpha_identifier">a</span> <span class="syntax_alpha syntax_alpha_reservedWord">ON</span> <span class="syntax_alpha syntax_alpha_identifier">b</span><span class="syntax_punct syntax_punct_qualifier">.</span><span class="syntax_quote syntax_quote_backtick">`PHONE`</span>  <span class="syntax_punct">=</span> <span class="syntax_alpha syntax_alpha_identifier">a</span><span class="syntax_punct syntax_punct_qualifier">.</span><span class="syntax_quote syntax_quote_backtick">`PHONE`</span> <span class="syntax_white syntax_white_newline" /><br />
<span class="syntax_alpha syntax_alpha_reservedWord">WHERE</span> <span class="syntax_alpha syntax_alpha_identifier">a</span><span class="syntax_punct syntax_punct_qualifier">.</span><span class="syntax_quote syntax_quote_backtick">`PHONE`</span>  <span class="syntax_alpha syntax_alpha_reservedWord">IS</span>  <span class="syntax_alpha syntax_alpha_reservedWord">NULL</span> </span></p>
<p>This should do it.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.tanhaa.net%2Findex.php%2F2007%2F06%2F15%2Fmysql-non-matching-records%2F&amp;title=MySQL%20non-matching%20Records" id="wpa2a_6"><img src="http://www.tanhaa.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.tanhaa.net/index.php/2007/06/15/mysql-non-matching-records/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mysql &#8211; matching records</title>
		<link>http://www.tanhaa.net/index.php/2007/03/12/mysql-matching-records/</link>
		<comments>http://www.tanhaa.net/index.php/2007/03/12/mysql-matching-records/#comments</comments>
		<pubDate>Mon, 12 Mar 2007 17:47:33 +0000</pubDate>
		<dc:creator>tanhaa</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[techno-babble]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.tanhaa.net/index.php/2007/03/12/mysql-matching-records/</guid>
		<description><![CDATA[Problem: Find records that match within two tables, TableA and TableB. Solution: Use a simple SELECT statement with a defined WHERE clause Lets assume that TableA and TableB have a field called “Phone” which contains the phone number of the clients and these numbers are obviously stored in a unique index. So what we are [...]]]></description>
			<content:encoded><![CDATA[<p>Problem:<br />
Find records that match within two tables, TableA and TableB.</p>
<p>Solution:</p>
<p>Use a simple SELECT statement with a defined WHERE clause</p>
<p>Lets assume that TableA and TableB have a field called “Phone” which contains the phone number of the clients and these numbers are obviously stored in a unique index.  So what we are going to do is run a simple query to find out which numbers in TableB match TableA.</p>
<p>Assuming you are using linux and you can run this query from the command prompt, this is the way to do it:</p>
<p>user@server:~/ mysql -u USERNAME -p<br />
(the server will ask for your password, enter the password and press Enter)</p>
<p>Now you should be in mysql and the prompt should look different already</p>
<p>mysql> use DATABASENAME<br />
(this command changes the database to the one where you have both the tables)<br />
mysql> select * FROM TableB, TableA WHERE TableB.phone=TableA.phone;</p>
<p>This query will obviously select all fields from TableB and TableA.  If you only wanted to select certain fields (for example &#8220;name&#8221; from TableB and &#8220;name&#8221; from TableA), then the query would change to:</p>
<p>mysql> select TableB.name, TableA.name FROM TableB, TableA WHERE TableB.phone=TableA.phone;</p>
<p>This will give you just the name column from TableB and name column from TableB.</p>
<p>Now what if you wanted to dump the query result into a text file for future use? Here&#8217;s the query:</p>
<p>mysql> SELECT TableB.name, TableA.name FROM TableB, TableA WHERE TableB.phone=TableA.phone INTO OUTFILE ‘/tmp/matchingnames.txt&#8217;;</p>
<p>That should do it.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.tanhaa.net%2Findex.php%2F2007%2F03%2F12%2Fmysql-matching-records%2F&amp;title=mysql%20%26%238211%3B%20matching%20records" id="wpa2a_8"><img src="http://www.tanhaa.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.tanhaa.net/index.php/2007/03/12/mysql-matching-records/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mysql &#8211; scrubbing files against others</title>
		<link>http://www.tanhaa.net/index.php/2007/03/12/mysql-scrubbing-files-against-others/</link>
		<comments>http://www.tanhaa.net/index.php/2007/03/12/mysql-scrubbing-files-against-others/#comments</comments>
		<pubDate>Mon, 12 Mar 2007 17:31:23 +0000</pubDate>
		<dc:creator>tanhaa</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[techno-babble]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.tanhaa.net/index.php/2007/03/12/mysql-scrubbing-files-against-others/</guid>
		<description><![CDATA[Problem: TableA contains a customer database TableB contains new names that you want to match against your customer database and remove all the names that are already customers. Solution: Use &#8220;LEFT JOIN&#8221; property of mysql to carry out the task. Lets assume that TableA and TableB have a field called &#8220;Phone&#8221; which contains the phone [...]]]></description>
			<content:encoded><![CDATA[<p>Problem:</p>
<p>TableA contains a customer database<br />
TableB contains new names that you want to match against your customer database and remove all the names that are already customers.</p>
<p>Solution:</p>
<p>Use &#8220;LEFT JOIN&#8221; property of mysql to carry out the task.</p>
<p>Lets assume that TableA and TableB have a field called &#8220;Phone&#8221; which contains the phone number of the clients and these numbers are obviously stored in a unique index.  So what we are going to do is run a simple query to find out which numbers in TableB do not exist in TableA.</p>
<p>Assuming you are using linux and you can run this query from the command prompt, this is the way to do it:</p>
<p>user@server:~/ mysql -u USERNAME -p<br />
(the server will ask for your password, enter the password and press Enter)</p>
<p>Now you should be in mysql and the prompt should look different already</p>
<p>mysql> use DATABASENAME<br />
(this command changes the database to the one where you have both the tables)<br />
mysql> select * from TableB LEFT JOIN TableA ON TableB.phone=TableA.phone WHERE TableA.phone IS NULL;</p>
<p>This should show you all the names in TableA that do not have a match in TableB.</p>
<p>Suppose you wanted to dump this file into a .txt file so you could use it elsewhere, the above command would change to:<br />
mysql> SELECT * FROM TableB LEFT JOIN TableA ON TableB.phone=TableA.phone WHERE TableA.phone IS NULL INTO OUTFILE &#8216;/tmp/scrubbedfilename.txt&#8217;;</p>
<p>This will dump the file with the unmatching records from TableA in the /tmp directory of your linux filesystem.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.tanhaa.net%2Findex.php%2F2007%2F03%2F12%2Fmysql-scrubbing-files-against-others%2F&amp;title=mysql%20%26%238211%3B%20scrubbing%20files%20against%20others" id="wpa2a_10"><img src="http://www.tanhaa.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.tanhaa.net/index.php/2007/03/12/mysql-scrubbing-files-against-others/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

