<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0" xmlns:blogChannel="http://backend.userland.com/blogChannelModule">

<channel>
<title>Re: how to write SQL query in Webmasters and Developers</title>
<link>http://www.dslreports.com/forum/r20442317</link>
<description></description>
<language>en</language>
<pubDate>Tue, 02 Dec 2008 19:53:03 EDT</pubDate>
<lastBuildDate>Tue, 02 Dec 2008 19:53:03 EDT</lastBuildDate>

<item>
<title>Re: how to write SQL query</title>
<link>http://www.dslreports.com/forum/remark,20466180</link>
<description><![CDATA[<A HREF="/useremail/u/359759"><b>Ray</b></A> : That's what I was thinking.  It's slow because that subselect is re-run for every row in the outer query.  First, I'd create an index on the comment date if there isn't one already and see if that becomes acceptable.  <br><br>Secondly, I'd try to make a query of the latest comment for each invoice a one-time deal as part of the FROM clause using a table alias.  I'd need to create some test data & play with it for a while to actually give you some specific SQL, but something along the lines of <br><br>SELECT i.blah, c.comment<br>FROM invoices i<br>JOIN (SELECT <i>most recent comment for each invoice</i>) c<br>ON (c.invoice_id = i.invoice_id)<br><small>--<br>ON DELETE CASCADE</small>]]></description>
<guid isPermaLink="true">http://www.dslreports.com/forum/remark,20466180</guid>
<pubDate>Sun, 11 May 2008 16:46:37 EDT</pubDate>
</item>

<item>
<title>Re: how to write SQL query</title>
<link>http://www.dslreports.com/forum/remark,20449954</link>
<description><![CDATA[<A HREF="/useremail/u/449413"><b>jayco437</b></A> : I don't know anything about DB2, but my first thought if I was doing this in Postgres would to analyze the table and check the indexes.<br><br>Can you change the select max() to a select.... order by comments.date desc limit 1, and notice any improvement?]]></description>
<guid isPermaLink="true">http://www.dslreports.com/forum/remark,20449954</guid>
<pubDate>Thu, 08 May 2008 04:41:39 EDT</pubDate>
</item>

<item>
<title>Re: how to write SQL query</title>
<link>http://www.dslreports.com/forum/remark,20446787</link>
<description><![CDATA[<A HREF="/useremail/u/265967"><b>dropshadow</b></A> : thank you.  your solution does indeed work, however it is slow.  any way to speed this up?  anyone? i want to avoid a subquery if possible, because that's slowing me down...]]></description>
<guid isPermaLink="true">http://www.dslreports.com/forum/remark,20446787</guid>
<pubDate>Wed, 07 May 2008 16:06:47 EDT</pubDate>
</item>

<item>
<title>Re: how to write SQL query</title>
<link>http://www.dslreports.com/forum/remark,20442361</link>
<description><![CDATA[<A HREF="/useremail/u/644121"><b>PetePuma</b></A> : I'd probably do something like<br><br><textarea name="code" class="text" cols=50 rows=10>select &#012;i.invoiceNumber, &#012;i.invoiceAmount,&#012;c.invoiceComment&#012;from invoices i&#012;inner join comments c&#012; on i.invoicenumber = c.invoicenumber&#012; and c.date = (select max(comments.date) from comments &#012;            where c.invoicenumber = comments.invoicenumber)&#012;</textarea><!--end code block--><br>I think that would work on DB2, it's been a while.<br><br>Disclaimer: done without syntax checking.<br>]]></description>
<guid isPermaLink="true">http://www.dslreports.com/forum/remark,20442361</guid>
<pubDate>Tue, 06 May 2008 20:45:49 EDT</pubDate>
</item>

<item>
<title>Re: how to write SQL query</title>
<link>http://www.dslreports.com/forum/remark,20442317</link>
<description><![CDATA[<A HREF="/useremail/u/265967"><b>dropshadow</b></A> : sorry, yes, by timestamp...so something like comments.dateCreated or something, i don't have the db in front of me atm...]]></description>
<guid isPermaLink="true">http://www.dslreports.com/forum/remark,20442317</guid>
<pubDate>Tue, 06 May 2008 20:36:19 EDT</pubDate>
</item>

<item>
<title>Re: how to write SQL query</title>
<link>http://www.dslreports.com/forum/remark,20441886</link>
<description><![CDATA[<A HREF="/useremail/u/644121"><b>PetePuma</b></A> : How do you determine what is the most recent invoice comment?  Is there a timestamp column?  Do you want the one with the highest identity?]]></description>
<guid isPermaLink="true">http://www.dslreports.com/forum/remark,20441886</guid>
<pubDate>Tue, 06 May 2008 19:10:43 EDT</pubDate>
</item>

<item>
<title>how to write SQL query</title>
<link>http://www.dslreports.com/forum/remark,20441608</link>
<description><![CDATA[<A HREF="/useremail/u/265967"><b>dropshadow</b></A> : i have a table with invoices.  i have another table with invoice comments.  what i want to do is perform a join, but only retrieve the most recent comment for each invoice.<br><br>basically, what i would like to do is this:<br><br>select invoices.invoiceNumber, invoices.invoiceAmount, TOP 1 comments.invoiceComment, from invoices inner join comments on invoices.invoiceNumber = comments.invoiceNumber.<br><br>however, my db does not seem to like this syntax.  i am on an IBM DB2.  it basically understands standard SQL.  is there another way to write this statement?  what i do not want retrieved is multiple lines of invoices since there are sometimes many comments per invoice.]]></description>
<guid isPermaLink="true">http://www.dslreports.com/forum/remark,20441608</guid>
<pubDate>Tue, 06 May 2008 18:20:30 EDT</pubDate>
</item>

</channel>
</rss>
