<?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>MySQL Diary &#187; Cool MySQL Queries Archives  &#8211; MySQL Diary</title> <atom:link href="http://www.mysqldiary.com/category/cool-mysql-queries/feed/" rel="self" type="application/rss+xml" /><link>http://www.mysqldiary.com</link> <description>Exploring, Sharing and  Discussing MySQL practice</description> <lastBuildDate>Mon, 18 Jul 2011 20:03:03 +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 Left Join</title><link>http://www.mysqldiary.com/mysql-left-join/</link> <comments>http://www.mysqldiary.com/mysql-left-join/#comments</comments> <pubDate>Wed, 06 Jul 2011 09:23:47 +0000</pubDate> <dc:creator>Hazan Ilan</dc:creator> <category><![CDATA[Cool MySQL Queries]]></category> <category><![CDATA[is null]]></category> <category><![CDATA[left join]]></category> <category><![CDATA[on]]></category> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=234</guid> <description><![CDATA[<div
class="addthis_toolbox addthis_default_style " addthis:url='http://www.mysqldiary.com/mysql-left-join/' addthis:title='MySQL Left Join '  ><a
class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a
class="addthis_button_tweet"></a><a
class="addthis_counter addthis_pill_style"></a></div>Even if you think you know everything about LEFT JOIN, I bet you will learn something or two in this post! A reminder about &#8220;A LEFT JOIN B ON conditional_expr&#8221; The ON condition (in the expression &#8220;A LEFT JOIN B ON conditional_expr&#8221;) is used to decide how to retrieve rows from table B (Matching-Stage). If [...]<div
class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.mysqldiary.com/mysql-left-join/' addthis:title='MySQL Left Join ' ><a
class="addthis_button_preferred_1"></a><a
class="addthis_button_preferred_2"></a><a
class="addthis_button_preferred_3"></a><a
class="addthis_button_preferred_4"></a><a
class="addthis_button_compact"></a></div>]]></description> <wfw:commentRss>http://www.mysqldiary.com/mysql-left-join/feed/</wfw:commentRss> <slash:comments>8</slash:comments> </item> <item><title>As restoring a dump table into the MySQL master &#8211; you better get some sleep</title><link>http://www.mysqldiary.com/as-restoring-a-dump-table-into-the-mysql-master-you-better-get-some-sleep/</link> <comments>http://www.mysqldiary.com/as-restoring-a-dump-table-into-the-mysql-master-you-better-get-some-sleep/#comments</comments> <pubDate>Mon, 04 Apr 2011 08:09:45 +0000</pubDate> <dc:creator>Hazan Ilan</dc:creator> <category><![CDATA[Cool MySQL Queries]]></category> <category><![CDATA[MySQL Script]]></category> <category><![CDATA[mysqldump]]></category> <category><![CDATA[sleep]]></category> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=198</guid> <description><![CDATA[<div
class="addthis_toolbox addthis_default_style " addthis:url='http://www.mysqldiary.com/as-restoring-a-dump-table-into-the-mysql-master-you-better-get-some-sleep/' addthis:title='As restoring a dump table into the MySQL master &#8211; you better get some sleep '  ><a
class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a
class="addthis_button_tweet"></a><a
class="addthis_counter addthis_pill_style"></a></div>Restoring a dump table into the MySQL master server can lead to serious replication delay. The massive inserts commands cause the Master and slaves to use most of their resources for replication. As a result, replication lag may increase dramatically (linear to the table size). To overcome the replication delay, caused by restoring the dump [...]<div
class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.mysqldiary.com/as-restoring-a-dump-table-into-the-mysql-master-you-better-get-some-sleep/' addthis:title='As restoring a dump table into the MySQL master &#8211; you better get some sleep ' ><a
class="addthis_button_preferred_1"></a><a
class="addthis_button_preferred_2"></a><a
class="addthis_button_preferred_3"></a><a
class="addthis_button_preferred_4"></a><a
class="addthis_button_compact"></a></div>]]></description> <wfw:commentRss>http://www.mysqldiary.com/as-restoring-a-dump-table-into-the-mysql-master-you-better-get-some-sleep/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>If you copy a MyISAM table with PRIMARY key, don’t forget to order the rows first</title><link>http://www.mysqldiary.com/if-you-copy-a-myisam-table-with-primary-key-don%e2%80%99t-forget-to-order-the-rows-first/</link> <comments>http://www.mysqldiary.com/if-you-copy-a-myisam-table-with-primary-key-don%e2%80%99t-forget-to-order-the-rows-first/#comments</comments> <pubDate>Mon, 14 Mar 2011 19:02:23 +0000</pubDate> <dc:creator>Hazan Ilan</dc:creator> <category><![CDATA[Cool MySQL Queries]]></category> <category><![CDATA[MySQL feature]]></category> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=189</guid> <description><![CDATA[<div
class="addthis_toolbox addthis_default_style " addthis:url='http://www.mysqldiary.com/if-you-copy-a-myisam-table-with-primary-key-don%e2%80%99t-forget-to-order-the-rows-first/' addthis:title='If you copy a MyISAM table with PRIMARY key, don’t forget to order the rows first '  ><a
class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a
class="addthis_button_tweet"></a><a
class="addthis_counter addthis_pill_style"></a></div>In a case that you copy (INSERT INTO .. SELECT ..) a MyISAM table that have a PRIMARY key, it is much faster to insert the new rows in the primary key order: The insertion will be faster: because the primary key cannot disabled, every insertion will also updates the primary key. In a case [...]<div
class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.mysqldiary.com/if-you-copy-a-myisam-table-with-primary-key-don%e2%80%99t-forget-to-order-the-rows-first/' addthis:title='If you copy a MyISAM table with PRIMARY key, don’t forget to order the rows first ' ><a
class="addthis_button_preferred_1"></a><a
class="addthis_button_preferred_2"></a><a
class="addthis_button_preferred_3"></a><a
class="addthis_button_preferred_4"></a><a
class="addthis_button_compact"></a></div>]]></description> <wfw:commentRss>http://www.mysqldiary.com/if-you-copy-a-myisam-table-with-primary-key-don%e2%80%99t-forget-to-order-the-rows-first/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>A many to many relationship table – solving the exclude relation problem</title><link>http://www.mysqldiary.com/a-many-to-many-relationship-table-solving-the-exclude-relation-problem/</link> <comments>http://www.mysqldiary.com/a-many-to-many-relationship-table-solving-the-exclude-relation-problem/#comments</comments> <pubDate>Tue, 18 Jan 2011 12:36:07 +0000</pubDate> <dc:creator>Hazan Ilan</dc:creator> <category><![CDATA[Cool MySQL Queries]]></category> <category><![CDATA[exclude]]></category> <category><![CDATA[inner query]]></category> <category><![CDATA[many to many]]></category> <category><![CDATA[pivot]]></category> <category><![CDATA[relation]]></category> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=138</guid> <description><![CDATA[<div
class="addthis_toolbox addthis_default_style " addthis:url='http://www.mysqldiary.com/a-many-to-many-relationship-table-solving-the-exclude-relation-problem/' addthis:title='A many to many relationship table – solving the exclude relation problem '  ><a
class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a
class="addthis_button_tweet"></a><a
class="addthis_counter addthis_pill_style"></a></div>I will start by defining the MySQL Many to Many relationship (Experts can skip to the next paragraph) What is A MySQL many to many relationship A MySQL many to many relationship is a relationship that is multi-valued in both directions. This type of relationship is helped by the use of a linking table. For [...]<div
class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.mysqldiary.com/a-many-to-many-relationship-table-solving-the-exclude-relation-problem/' addthis:title='A many to many relationship table – solving the exclude relation problem ' ><a
class="addthis_button_preferred_1"></a><a
class="addthis_button_preferred_2"></a><a
class="addthis_button_preferred_3"></a><a
class="addthis_button_preferred_4"></a><a
class="addthis_button_compact"></a></div>]]></description> <wfw:commentRss>http://www.mysqldiary.com/a-many-to-many-relationship-table-solving-the-exclude-relation-problem/feed/</wfw:commentRss> <slash:comments>9</slash:comments> </item> <item><title>The battle between FORCE INDEX and the QUERY OPTIMIZER</title><link>http://www.mysqldiary.com/the-battle-between-force-index-and-the-query-optimizer/</link> <comments>http://www.mysqldiary.com/the-battle-between-force-index-and-the-query-optimizer/#comments</comments> <pubDate>Mon, 25 Oct 2010 21:15:41 +0000</pubDate> <dc:creator>Hazan Ilan</dc:creator> <category><![CDATA[Cool MySQL Queries]]></category> <category><![CDATA[MySQL feature]]></category> <category><![CDATA[analyze table]]></category> <category><![CDATA[Cardinality]]></category> <category><![CDATA[Force Index]]></category> <category><![CDATA[key distributions]]></category> <category><![CDATA[MySQL optimizer]]></category> <category><![CDATA[QUERY OPTIMIZER]]></category> <category><![CDATA[Use Index]]></category> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=146</guid> <description><![CDATA[<div
class="addthis_toolbox addthis_default_style " addthis:url='http://www.mysqldiary.com/the-battle-between-force-index-and-the-query-optimizer/' addthis:title='The battle between FORCE INDEX and the QUERY OPTIMIZER '  ><a
class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a
class="addthis_button_tweet"></a><a
class="addthis_counter addthis_pill_style"></a></div>Query Optimizer is a part of the server that takes a parsed SQL query and produces a query execution plan. MySQL Query Optimizer uses (as one of its parameters) the stored key distribution (Cardinality) mechanism to determine the order in which tables should be joined, when you perform a join on something other than a [...]<div
class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.mysqldiary.com/the-battle-between-force-index-and-the-query-optimizer/' addthis:title='The battle between FORCE INDEX and the QUERY OPTIMIZER ' ><a
class="addthis_button_preferred_1"></a><a
class="addthis_button_preferred_2"></a><a
class="addthis_button_preferred_3"></a><a
class="addthis_button_preferred_4"></a><a
class="addthis_button_compact"></a></div>]]></description> <wfw:commentRss>http://www.mysqldiary.com/the-battle-between-force-index-and-the-query-optimizer/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Optimizing the MySQL IN() Comparison Operations Which Include the Indexed Field</title><link>http://www.mysqldiary.com/optimizing-the-mysql-in-comparison-operations-which-include-the-indexed-field/</link> <comments>http://www.mysqldiary.com/optimizing-the-mysql-in-comparison-operations-which-include-the-indexed-field/#comments</comments> <pubDate>Thu, 07 Oct 2010 12:06:13 +0000</pubDate> <dc:creator>Hazan Ilan</dc:creator> <category><![CDATA[Cool MySQL Queries]]></category> <category><![CDATA[Comparison operator]]></category> <category><![CDATA[IN]]></category> <category><![CDATA[MySQL IN]]></category> <category><![CDATA[performance]]></category> <category><![CDATA[query]]></category> <category><![CDATA[union all]]></category> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=128</guid> <description><![CDATA[<div
class="addthis_toolbox addthis_default_style " addthis:url='http://www.mysqldiary.com/optimizing-the-mysql-in-comparison-operations-which-include-the-indexed-field/' addthis:title='Optimizing the MySQL IN() Comparison Operations Which Include the Indexed Field '  ><a
class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a
class="addthis_button_tweet"></a><a
class="addthis_counter addthis_pill_style"></a></div>The MySQL IN() Comparison Operator is said to be very quick if all the values are constants (the values are then evaluated and sorted first, and the search is done using a binary search). However, what if the field which the IN clause refers to, is part of the index used to execute the query? [...]<div
class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.mysqldiary.com/optimizing-the-mysql-in-comparison-operations-which-include-the-indexed-field/' addthis:title='Optimizing the MySQL IN() Comparison Operations Which Include the Indexed Field ' ><a
class="addthis_button_preferred_1"></a><a
class="addthis_button_preferred_2"></a><a
class="addthis_button_preferred_3"></a><a
class="addthis_button_preferred_4"></a><a
class="addthis_button_compact"></a></div>]]></description> <wfw:commentRss>http://www.mysqldiary.com/optimizing-the-mysql-in-comparison-operations-which-include-the-indexed-field/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>Limited SELECT count(*)</title><link>http://www.mysqldiary.com/limited-select-count/</link> <comments>http://www.mysqldiary.com/limited-select-count/#comments</comments> <pubDate>Thu, 13 May 2010 21:52:43 +0000</pubDate> <dc:creator>Hazan Ilan</dc:creator> <category><![CDATA[Cool MySQL Queries]]></category> <category><![CDATA[count(*)]]></category> <category><![CDATA[limit]]></category> <category><![CDATA[limited count]]></category> <category><![CDATA[performance]]></category> <category><![CDATA[select]]></category> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=98</guid> <description><![CDATA[<div
class="addthis_toolbox addthis_default_style " addthis:url='http://www.mysqldiary.com/limited-select-count/' addthis:title='Limited SELECT count(*) '  ><a
class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a
class="addthis_button_tweet"></a><a
class="addthis_counter addthis_pill_style"></a></div>A SELECT statement with COUNT returns the number of rows retrieved by the SELECT statement (see mysql select count). For performance reasons, the desired result is to limit that count. Including a LIMIT clause in the SELECT statement will not work since it only restricts the number of rows returned, which is always one. The [...]<div
class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.mysqldiary.com/limited-select-count/' addthis:title='Limited SELECT count(*) ' ><a
class="addthis_button_preferred_1"></a><a
class="addthis_button_preferred_2"></a><a
class="addthis_button_preferred_3"></a><a
class="addthis_button_preferred_4"></a><a
class="addthis_button_compact"></a></div>]]></description> <wfw:commentRss>http://www.mysqldiary.com/limited-select-count/feed/</wfw:commentRss> <slash:comments>23</slash:comments> </item> <item><title>Conditional Joins in MySQL</title><link>http://www.mysqldiary.com/conditional-joins-in-mysql/</link> <comments>http://www.mysqldiary.com/conditional-joins-in-mysql/#comments</comments> <pubDate>Sun, 07 Feb 2010 19:43:12 +0000</pubDate> <dc:creator>Hazan Ilan</dc:creator> <category><![CDATA[Cool MySQL Queries]]></category> <category><![CDATA[conditional join]]></category> <category><![CDATA[join in Mysql]]></category> <category><![CDATA[left join]]></category> <category><![CDATA[mysql join]]></category> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=71</guid> <description><![CDATA[<div
class="addthis_toolbox addthis_default_style " addthis:url='http://www.mysqldiary.com/conditional-joins-in-mysql/' addthis:title='Conditional Joins in MySQL '  ><a
class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a
class="addthis_button_tweet"></a><a
class="addthis_counter addthis_pill_style"></a></div>One way to do a “Conditional Join” in MySQL is by using a “LEFT JOIN”.  Create a “LEFT JOIN” for each condition and combine the results into one column using an “IF” statement by the “SELECT” expression.  Here’s an example: Suppose you have three tables: questions: a table consisting of question ids, timestamps, and whether [...]<div
class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.mysqldiary.com/conditional-joins-in-mysql/' addthis:title='Conditional Joins in MySQL ' ><a
class="addthis_button_preferred_1"></a><a
class="addthis_button_preferred_2"></a><a
class="addthis_button_preferred_3"></a><a
class="addthis_button_preferred_4"></a><a
class="addthis_button_compact"></a></div>]]></description> <wfw:commentRss>http://www.mysqldiary.com/conditional-joins-in-mysql/feed/</wfw:commentRss> <slash:comments>9</slash:comments> </item> <item><title>Selecting records from one table that dont have specific relationship in a second table</title><link>http://www.mysqldiary.com/selecting-records-from-one-table-that-dont-have-specific-relationship-in-a-second-table/</link> <comments>http://www.mysqldiary.com/selecting-records-from-one-table-that-dont-have-specific-relationship-in-a-second-table/#comments</comments> <pubDate>Sun, 17 Jan 2010 19:57:07 +0000</pubDate> <dc:creator>Hazan Ilan</dc:creator> <category><![CDATA[Cool MySQL Queries]]></category> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=58</guid> <description><![CDATA[<div
class="addthis_toolbox addthis_default_style " addthis:url='http://www.mysqldiary.com/selecting-records-from-one-table-that-dont-have-specific-relationship-in-a-second-table/' addthis:title='Selecting records from one table that dont have specific relationship in a second table '  ><a
class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a
class="addthis_button_tweet"></a><a
class="addthis_counter addthis_pill_style"></a></div>Question: How can you select records from one table that doesn’t have a specific ID in a second, many-to-many table?   In other words, imagine you have a questions table (A), categories table (B), and a many-to-many relationship link table (L).  This setup allows a question to have several categories.  How can you find questions that [...]<div
class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.mysqldiary.com/selecting-records-from-one-table-that-dont-have-specific-relationship-in-a-second-table/' addthis:title='Selecting records from one table that dont have specific relationship in a second table ' ><a
class="addthis_button_preferred_1"></a><a
class="addthis_button_preferred_2"></a><a
class="addthis_button_preferred_3"></a><a
class="addthis_button_preferred_4"></a><a
class="addthis_button_compact"></a></div>]]></description> <wfw:commentRss>http://www.mysqldiary.com/selecting-records-from-one-table-that-dont-have-specific-relationship-in-a-second-table/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>How to produce random rows from a table</title><link>http://www.mysqldiary.com/how-to-produce-random-rows-from-a-table/</link> <comments>http://www.mysqldiary.com/how-to-produce-random-rows-from-a-table/#comments</comments> <pubDate>Sun, 29 Nov 2009 04:10:30 +0000</pubDate> <dc:creator>Hazan Ilan</dc:creator> <category><![CDATA[Cool MySQL Queries]]></category> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=20</guid> <description><![CDATA[<div
class="addthis_toolbox addthis_default_style " addthis:url='http://www.mysqldiary.com/how-to-produce-random-rows-from-a-table/' addthis:title='How to produce random rows from a table '  ><a
class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a
class="addthis_button_tweet"></a><a
class="addthis_counter addthis_pill_style"></a></div>A while ago, I were searching for a way to produce random rows from a table in MySQL. I found several solutions but none of them satisfied me. Of course, I could use  a combined logic of MySQL and a programming language. For example by producing random numbers in PHP and using them in the MySQL query in a IN clouse.  However, I [...]<div
class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.mysqldiary.com/how-to-produce-random-rows-from-a-table/' addthis:title='How to produce random rows from a table ' ><a
class="addthis_button_preferred_1"></a><a
class="addthis_button_preferred_2"></a><a
class="addthis_button_preferred_3"></a><a
class="addthis_button_preferred_4"></a><a
class="addthis_button_compact"></a></div>]]></description> <wfw:commentRss>http://www.mysqldiary.com/how-to-produce-random-rows-from-a-table/feed/</wfw:commentRss> <slash:comments>18</slash:comments> </item> </channel> </rss>
