Re: [SQL] Rewrite without correlated subqueries

2009-08-20 Thread bricklen
On Thu, Aug 20, 2009 at 2:59 PM, Scott Marlowe wrote: > On Thu, Aug 20, 2009 at 3:16 PM, bricklen wrote: > > Interesting idea. Preferably this operation could be done in straight SQL > in > > a single transaction, to fit in with the way our application works, but > if > > that's not possible I may

Re: [SQL] Rewrite without correlated subqueries

2009-08-20 Thread Scott Marlowe
On Thu, Aug 20, 2009 at 3:16 PM, bricklen wrote: > Interesting idea. Preferably this operation could be done in straight SQL in > a single transaction, to fit in with the way our application works, but if > that's not possible I may need to go the temporary table route. Temp tables can be included

Re: [SQL] Rewrite without correlated subqueries

2009-08-20 Thread bricklen
Interesting idea. Preferably this operation could be done in straight SQL in a single transaction, to fit in with the way our application works, but if that's not possible I may need to go the temporary table route. On Thu, Aug 20, 2009 at 1:40 PM, Mark Fenbers wrote: > Try putting your subquer

Re: [SQL] Rewrite without correlated subqueries

2009-08-20 Thread Mark Fenbers
Try putting your subqueries into temporary tables, first, inside a BEGIN ... COMMIT block.  But your subqueries would produce the negative, i.e., everything except where sitescategory.idsites = ps.idsites.  Then reference these temp tables in your query with inner or outer joins as appropriate.

[SQL] Rewrite without correlated subqueries

2009-08-20 Thread bricklen
Hi All, I'm having some trouble wrapping my head around the syntax to rewrite a query using correlated subqueries, to using outer joins etc. The query: SELECT ps.userid, SUM( ps.hits ) as numhits FROM primarystats AS ps INNER JOIN camp ON camp.id = ps.idcamp INNER JOIN sites