<?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>Flash Flood &#187; mySQL</title>
	<atom:link href="http://eddieoleary.com/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://eddieoleary.com</link>
	<description>Flash CS3 and Actionscript 3 discussions</description>
	<lastBuildDate>Tue, 14 Jul 2009 18:11:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SQL Trick: Selecting unique records.</title>
		<link>http://eddieoleary.com/2008/06/13/sql-trick-selecting-unique-records/</link>
		<comments>http://eddieoleary.com/2008/06/13/sql-trick-selecting-unique-records/#comments</comments>
		<pubDate>Fri, 13 Jun 2008 14:00:28 +0000</pubDate>
		<dc:creator>Eddie</dc:creator>
				<category><![CDATA[mySQL]]></category>

		<guid isPermaLink="false">http://eddieoleary.com/?p=13</guid>
		<description><![CDATA[The Situation:
I have a bunch of records.  They are items with five or so fields.  One of the fields is the artist that created the item (artist_id).  I needed to pull just one item from each artist and I needed all the other fields associated with each item.  I tried:
PLAIN TEXT
SQL:




SELECT [...]]]></description>
			<content:encoded><![CDATA[<p>The Situation:<br />
I have a bunch of records.  They are items with five or so fields.  One of the fields is the artist that created the item (artist_id).  I needed to pull just one item from each artist and I needed all the other fields associated with each item.  I tried:</p>
<div class="igBar"><span id="lsql-3"><a href="#" onclick="javascript:showPlainTxt('sql-3'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-3">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">DISTINCT</span> artist_id <span style="color: #993333; font-weight: bold;">FROM</span> items <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> artist_id <span style="color: #993333; font-weight: bold;">ASC</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>This partially did what I wanted.  It returns all the UNIQUE artist_id.  I want essentially a sample item for EACH artist.</p>
<p>The Solution:</p>
<div class="igBar"><span id="lsql-4"><a href="#" onclick="javascript:showPlainTxt('sql-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-4">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">SELECT</span> *, COUNT<span style="color:#006600; font-weight:bold;">&#40;</span>artist_id<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> items <span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> artist_id <span style="color: #993333; font-weight: bold;">HAVING</span> COUNT<span style="color:#006600; font-weight:bold;">&#40;</span>artist_id<span style="color:#006600; font-weight:bold;">&#41;</span>&amp;gt;=<span style="color: #cc66cc;color:#800000;">1</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>This returns ONE row for each artist.  I found this on a blog, I cant remember the name but when I find it again I will post credit.  I hope this helps some of you.</p>
]]></content:encoded>
			<wfw:commentRss>http://eddieoleary.com/2008/06/13/sql-trick-selecting-unique-records/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
