Search:  

 
 
   All ForumsHot TopicsGallery






how-to block ads


 
Forums » Tech and Talk » OS and Software » Webmasters and Developers » how to write SQL query
Search Topic:
Share Topic:
RSS topic:
toggle:
flat / full
normal / watch
Posting:
Post a:
Post a:
I need some of you guys help on here. »
« Anyone here familar with CS3 Flash?  
AuthorAll Replies


dropshadow

join:2000-12-17
Plano, TX
clubs:

edit:
May 6th, @08:37PM

reply to PetePuma
Re: how to write SQL query

sorry, yes, by timestamp...so something like comments.dateCreated or something, i don't have the db in front of me atm...


PetePuma
How many lumps do you want
Premium,MVM
join:2002-06-13
Arlington, VA

I'd probably do something like


I think that would work on DB2, it's been a while.

Disclaimer: done without syntax checking.


dropshadow

join:2000-12-17
Plano, TX
clubs:

edit:
May 7th, @04:45PM

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...


jayco437
Premium
join:2001-08-11
Lincoln, NE
·Windstream
·AT&T Southwest

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.

Can you change the select max() to a select.... order by comments.date desc limit 1, and notice any improvement?


Ray
Mahnahmahna
Premium
join:2001-04-02
Mesa, AZ


edit:
May 11th, @04:47PM

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.

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

SELECT i.blah, c.comment
FROM invoices i
JOIN (SELECT most recent comment for each invoice) c
ON (c.invoice_id = i.invoice_id)
--
ON DELETE CASCADE
Forums » Tech and Talk » OS and Software » Webmasters and DevelopersI need some of you guys help on here. »
« Anyone here familar with CS3 Flash?  


Tuesday, 02-Dec 19:59:27 Terms of Use | Privacy Policy | Hosting by www.nac.net - DSL,Hosting & Co-lo | feedback | contact
over 9 years online! © 1999-2008 dslreports.com.
page compression OFF
Most commented news this week
· [111] AT&T Metered Billing Trial Hits Second Market
· [83] UDP BitTorrent Will Destroy The Interwebs!
· [67] EFF Challenges Telecom Immunity
· [60] Comcast Tries To Slow Verizon's Philly Entry
· [36] Cablevision Bumps HD Count To 68
· [32] Verizon Tops Consumer Reports Wireless Satisfaction Ratings
· [27] Mega-ISPs, Consumer Advocates Demand Broadband Plan
· [26] Hawaii Telecom Files For Bankruptcy
· [24] T-Mobile Invisible Caps Return
· [24] Comcast To Offer Bandwidth Use Tracker In January
Most people now reading
· [Rant] Bestbuy receipt checker [Rants, Raves, & Praise]
· Is this a good thing for the net? [news,99366]
· Coalition Government Possible? [TekSavvy]
· Level 80 PVP gear info? [World of Warcraft]
· Notice, new uTorrent Alpha may be able to evade throttling [TekSavvy]
· [WotLK] Starting the Rep Grind [World of Warcraft]
· Java SE Runtime Environment (JRE) 6 Update 11 [Security]
· [WotLK] New Hunter Macros [World of Warcraft]
· It's official ... Macs need anti-virus software [Security]
· Ted Rogers passed away [Rogers]