Re[SQL] write multiple joins...

2009-08-20 Thread tripplowe
Hey Folks, I have a query that seems like it will never end. I'm hoping you can help me rewrite it. I have 4 tables that contain information about house sales within the state (sale, taxes, property, buyer). Each table has an 'id' field that links each record. I am just trying to flatten thes

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

Re: [SQL] using case to select 'which version to use'

2009-08-20 Thread Rodrigo E . De León Plicet
On Thu, Aug 20, 2009 at 10:17 AM, Gerardo Herzig wrote: > Hi all. I have 2 functions , which returns the same columns, but with > tottaly different logics. I want to wrap it with a third function, who > will receive a boolean argument to decide wich sub-function have to use. > > I want to use case,

[SQL] using case to select 'which version to use'

2009-08-20 Thread Gerardo Herzig
Hi all. I have 2 functions , which returns the same columns, but with tottaly different logics. I want to wrap it with a third function, who will receive a boolean argument to decide wich sub-function have to use. I want to use case, so i dont have to use pl/pgsql. This is a non-working example:

[SQL] Advice returning data as an array

2009-08-20 Thread George Woodring
I have the following query that works the way I need: SELECT '20090812' AS date, sum(in_oct) AS bytes, sum(in_pkt) AS pkts, 'appl' AS name, ARRAY['appl'] AS fields, CAST((LEAST(src_port, dst_port)) AS varchar) as fieldVal FROM flow_history.flows_20090812 GROUP BY fieldVal ORDER BY bytes DESC LIMIT

Re: [SQL] Updating one table with data from another

2009-08-20 Thread Jasen Betts
On 2009-08-18, drew wrote: > Hey all, > There are two things I need to do: > 1. Update existing rows with new data > 2. Append new rows > > I need to update only some of the fields table1 with data from > table2. These tables have the exact same fields. > > So here's what I have currently for app