republican-creole
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


jayco437
Premium
join:2001-08-11
El Paso, TX
·AT&T Southwest

reply to dropshadow
Re: how to write SQL query

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?  


Monday, 08-Sep 12:14:16 Terms of Use | Privacy Policy | Hosting by www.nac.net - DSL,Hosting & Co-lo | feedback | contact
over 9 years online! © 1999-2008 dslreports.com.republican-creole
page compression OFF
Most commented news this week
· [24] J.D. Power Ranks Wireless Call Quality
· [12] $40 Billion To Wire the UK With FTTH
· [7] Cox Offers Automated Backup Service
· [6] DSL Is The New Dial-Up
· [4] Monday Morning Links
Most people now reading
· Is my landlord trying to screw me (Updated)? [Home Repair & Improvement]
· What to do when selling and everyone loves it, but no offers [Home Repair & Improvement]
· [iPhone] Apps not working?? [All things Macintosh]
· Philly Metro VHO8 Update [Verizon FIOS TV]
· [new forum] Gay / Lesbian Talk [Forum Feature Requests]
· [XP Pro] Tweaking XP to take advantage of second HD [Microsoft help]
· Transfer switch [Home Repair & Improvement]
· Hurricane Ike [Weather]
· New "Recovery Fee" on T1 Contract [AT&T Midwest]
· One of my modems suspected dead, need new one for MLPPP [TekSavvy]