<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Memo: Avoid Nested Queries in MySQL at all costs</title>
	<atom:link href="http://www.selikoff.net/2008/12/10/memo-avoid-nested-queries-in-mysql-at-all-costs/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.selikoff.net/2008/12/10/memo-avoid-nested-queries-in-mysql-at-all-costs/</link>
	<description>Java/J2EE Software Development and Technology Discussion Blog</description>
	<lastBuildDate>Tue, 07 Feb 2012 22:20:38 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Scott Selikoff</title>
		<link>http://www.selikoff.net/2008/12/10/memo-avoid-nested-queries-in-mysql-at-all-costs/comment-page-1/#comment-4891</link>
		<dc:creator>Scott Selikoff</dc:creator>
		<pubDate>Sun, 08 Jan 2012 12:00:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.selikoff.net/blog/?p=652#comment-4891</guid>
		<description>You should focus on learning Database Joins, not MySQL Joins, as the concepts are the same across databases.  I&#039;d spend time learning the theory behind joins and then it won&#039;t seem to complicated.</description>
		<content:encoded><![CDATA[<p>You should focus on learning Database Joins, not MySQL Joins, as the concepts are the same across databases.  I&#8217;d spend time learning the theory behind joins and then it won&#8217;t seem to complicated.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Simon</title>
		<link>http://www.selikoff.net/2008/12/10/memo-avoid-nested-queries-in-mysql-at-all-costs/comment-page-1/#comment-4890</link>
		<dc:creator>Simon</dc:creator>
		<pubDate>Sun, 08 Jan 2012 11:56:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.selikoff.net/blog/?p=652#comment-4890</guid>
		<description>I&#039;m just starting to get into more complicated MYSQL queries as my job requires this but I can&#039;t understand them at all! does anyone know a good resource for learning about joining in mysql queries?</description>
		<content:encoded><![CDATA[<p>I&#8217;m just starting to get into more complicated MYSQL queries as my job requires this but I can&#8217;t understand them at all! does anyone know a good resource for learning about joining in mysql queries?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Are lots of queries faster in MySql than a big JOIN? &#124; Smash Company</title>
		<link>http://www.selikoff.net/2008/12/10/memo-avoid-nested-queries-in-mysql-at-all-costs/comment-page-1/#comment-2837</link>
		<dc:creator>Are lots of queries faster in MySql than a big JOIN? &#124; Smash Company</dc:creator>
		<pubDate>Sat, 25 Sep 2010 00:21:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.selikoff.net/blog/?p=652#comment-2837</guid>
		<description>[...] find this hard to believe, but I&#8217;ve now read it in several places. Some people seem to think that lots of queries are faster than big JOINs, in MySql. [...]</description>
		<content:encoded><![CDATA[<p>[...] find this hard to believe, but I&#8217;ve now read it in several places. Some people seem to think that lots of queries are faster than big JOINs, in MySql. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MySQL and nested queries &#171; Ablue Blog</title>
		<link>http://www.selikoff.net/2008/12/10/memo-avoid-nested-queries-in-mysql-at-all-costs/comment-page-1/#comment-2746</link>
		<dc:creator>MySQL and nested queries &#171; Ablue Blog</dc:creator>
		<pubDate>Sun, 05 Sep 2010 12:50:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.selikoff.net/blog/?p=652#comment-2746</guid>
		<description>[...] Here is a good blog post that describes the problem. [...]</description>
		<content:encoded><![CDATA[<p>[...] Here is a good blog post that describes the problem. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Clintonio</title>
		<link>http://www.selikoff.net/2008/12/10/memo-avoid-nested-queries-in-mysql-at-all-costs/comment-page-1/#comment-2647</link>
		<dc:creator>Clintonio</dc:creator>
		<pubDate>Fri, 06 Aug 2010 13:23:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.selikoff.net/blog/?p=652#comment-2647</guid>
		<description>Posting again, want it to notify me of replies. Silly me.</description>
		<content:encoded><![CDATA[<p>Posting again, want it to notify me of replies. Silly me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Clintonio</title>
		<link>http://www.selikoff.net/2008/12/10/memo-avoid-nested-queries-in-mysql-at-all-costs/comment-page-1/#comment-2646</link>
		<dc:creator>Clintonio</dc:creator>
		<pubDate>Fri, 06 Aug 2010 13:22:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.selikoff.net/blog/?p=652#comment-2646</guid>
		<description>Today I used my first nested query, and as such immedietely googled it. I&#039;ve been in databases a long time, and use joins, functions, unions, everything, on a regular basis, but nested queries always seemed messy to me, hard to organise and almost redundant. 

Today I needed one for the first time, and why? I did my query directly into the mysql terminal (I rarely do this).

I had to use:
SELECT
	count(t1.id_address), min(t1.id_address)
FROM
	address t1
WHERE
	id_address &gt;= (SELECT 
										min(id_address) 
								FROM 
										applicant t2
								WHERE
										dt_complete &gt; CURDATE() - INTERVAL 1 YEAR)
		

It&#039;s so messy. But it was a quick hack. I still see no alternative, since address is used by like 4 other tables.</description>
		<content:encoded><![CDATA[<p>Today I used my first nested query, and as such immedietely googled it. I&#8217;ve been in databases a long time, and use joins, functions, unions, everything, on a regular basis, but nested queries always seemed messy to me, hard to organise and almost redundant. </p>
<p>Today I needed one for the first time, and why? I did my query directly into the mysql terminal (I rarely do this).</p>
<p>I had to use:<br />
SELECT<br />
	count(t1.id_address), min(t1.id_address)<br />
FROM<br />
	address t1<br />
WHERE<br />
	id_address &gt;= (SELECT<br />
										min(id_address)<br />
								FROM<br />
										applicant t2<br />
								WHERE<br />
										dt_complete &gt; CURDATE() &#8211; INTERVAL 1 YEAR)</p>
<p>It&#8217;s so messy. But it was a quick hack. I still see no alternative, since address is used by like 4 other tables.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SomeWhat</title>
		<link>http://www.selikoff.net/2008/12/10/memo-avoid-nested-queries-in-mysql-at-all-costs/comment-page-1/#comment-2604</link>
		<dc:creator>SomeWhat</dc:creator>
		<pubDate>Mon, 19 Jul 2010 02:56:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.selikoff.net/blog/?p=652#comment-2604</guid>
		<description>Sincerely, I quite bitched while reading your answer, but your dogmatism paid off. I see now that the way should have been:

SELECT DISTINCT children.id_section, children.id_parent, children.barnav, children.lastmod
FROM sections children LEFT JOIN sections parents ON children.id_parent=parent.id_section
WHERE children.active=1
AND parents.active=1
ORDER BY children.id_parent;

Worked seemlessly.
Thanks -specially- for the wisdom within, man.</description>
		<content:encoded><![CDATA[<p>Sincerely, I quite bitched while reading your answer, but your dogmatism paid off. I see now that the way should have been:</p>
<p>SELECT DISTINCT children.id_section, children.id_parent, children.barnav, children.lastmod<br />
FROM sections children LEFT JOIN sections parents ON children.id_parent=parent.id_section<br />
WHERE children.active=1<br />
AND parents.active=1<br />
ORDER BY children.id_parent;</p>
<p>Worked seemlessly.<br />
Thanks -specially- for the wisdom within, man.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott Selikoff</title>
		<link>http://www.selikoff.net/2008/12/10/memo-avoid-nested-queries-in-mysql-at-all-costs/comment-page-1/#comment-2603</link>
		<dc:creator>Scott Selikoff</dc:creator>
		<pubDate>Mon, 19 Jul 2010 01:23:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.selikoff.net/blog/?p=652#comment-2603</guid>
		<description>@SomeWhat

That query can be easily rewritten using an inner join.  There&#039;s no rule saying that you cannot join a table on itself.  It would be a worthwhile exercise for you to figure out how to rewrite the query without using a nested join.</description>
		<content:encoded><![CDATA[<p>@SomeWhat</p>
<p>That query can be easily rewritten using an inner join.  There&#8217;s no rule saying that you cannot join a table on itself.  It would be a worthwhile exercise for you to figure out how to rewrite the query without using a nested join.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SomeWhat</title>
		<link>http://www.selikoff.net/2008/12/10/memo-avoid-nested-queries-in-mysql-at-all-costs/comment-page-1/#comment-2602</link>
		<dc:creator>SomeWhat</dc:creator>
		<pubDate>Mon, 19 Jul 2010 01:07:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.selikoff.net/blog/?p=652#comment-2602</guid>
		<description>Ok. But what about when you have hierarchical data, such as:

SELECT id_section, id_parent AS aka_parent, barnav, lastmod 
FROM sections 
WHERE active=1 
AND (SELECT active FROM sections WHERE id_section=aka_parent)=1
ORDER BY aka_parent;

There you need to use INSIDE the nested query a value retrieved as an alias in the main query. 
So, if you are looping this, and you go the distinct query way you may not get the same results. Isn&#039;t it?</description>
		<content:encoded><![CDATA[<p>Ok. But what about when you have hierarchical data, such as:</p>
<p>SELECT id_section, id_parent AS aka_parent, barnav, lastmod<br />
FROM sections<br />
WHERE active=1<br />
AND (SELECT active FROM sections WHERE id_section=aka_parent)=1<br />
ORDER BY aka_parent;</p>
<p>There you need to use INSIDE the nested query a value retrieved as an alias in the main query.<br />
So, if you are looping this, and you go the distinct query way you may not get the same results. Isn&#8217;t it?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: scott</title>
		<link>http://www.selikoff.net/2008/12/10/memo-avoid-nested-queries-in-mysql-at-all-costs/comment-page-1/#comment-624</link>
		<dc:creator>scott</dc:creator>
		<pubDate>Thu, 11 Dec 2008 23:19:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.selikoff.net/blog/?p=652#comment-624</guid>
		<description>Hi Tripy,
That&#039;s a good suggestion.  It feels a little bit like a hack, although I can&#039;t imagine the performance is worse than some of the things that happen with IN/NOT IN.

Thanks!
-Scott</description>
		<content:encoded><![CDATA[<p>Hi Tripy,<br />
That&#8217;s a good suggestion.  It feels a little bit like a hack, although I can&#8217;t imagine the performance is worse than some of the things that happen with IN/NOT IN.</p>
<p>Thanks!<br />
-Scott</p>
]]></content:encoded>
	</item>
</channel>
</rss>

