Re: [SQL] Join issue

2006-06-07 Thread operationsengineer1
> Table structures: > > ce_house > > house_id > provider_id > > ce_contract > > contract_id > house_id > contract_term > contract_created > > ce_contract_status > > contract_status_id > contract_id > contract_status > contract_status

Re: [SQL] Join issue

2006-06-07 Thread Burak Seydioglu
My current solution to the problem is PHP and it - simply put - sucks I loop through all the house records for a user using the following query SELECT * FROM ce_house LEFT JOIN ce_contract ON ce_house.house_id=ce_contract.house_id LEFT JOIN ce_contract_status

Re: [SQL] Join issue

2006-06-06 Thread Michael Glaesemann
On Jun 7, 2006, at 8:53 , Kenneth B Hill wrote: Make a "view" with a query, then perform a query using the view, etc. , then drop all views in the SQL script. This may make the entire operation perform faster. I don't know how using a view would improve performance. However, it may make the

Re: [SQL] Join issue

2006-06-06 Thread Kenneth B Hill
That looks like a very complex query. I would like to suggest that you try doing some nesting queries via a SQL script. Make a "view" with a query, then perform a query using the view, etc. , then drop all views in the SQL script. This may make the entire operation perform faster. -Ken On Tue, 20

Re: [SQL] Join issue

2006-06-06 Thread operationsengineer1
> Hi, > > I have one to many (from left to right) > relationships among the below tables > in my database > > user -> house -> contract -> contract status >| > > Also, a single house has a single provider and the > provider has multiple > rates inside the provider_rate table in >

Re: [SQL] Join issue

2006-06-06 Thread Andrew Sullivan
On Tue, Jun 06, 2006 at 11:10:46AM -0700, Burak Seydioglu wrote: > I have a query to return the latest contract and contract status for a > house... What i am trying to do is to get the rate of electricity for the > latest contract... I am trying to retrieve the latest provider rate before a > cont

[SQL] Join issue

2006-06-06 Thread Burak Seydioglu
Hi,I have one to many (from left to right) relationships among the below tables in my databaseuser -> house -> contract -> contract status   |Also, a single house has a single provider and the provider has multiple rates inside the provider_rate table in chronological order.I have a que

[SQL] Join issue?

2004-12-15 Thread Marian POPESCU
Hi, I have a problem with this join query: SELECT CASE WHEN (UR.id_rights IS NULL) THEN '0' ELSE UR.id_rights END as id_rights, CASE WHEN (UR.r_category IS NULL) THEN 'CMP' ELSE UR.r_category END as category, U.id as id_user, U.username FROM mgw_users U LEFT OUTER JOIN mgw_cnt_us

Re: [SQL] Join issue?

2004-12-15 Thread Stephan Szabo
On Wed, 15 Dec 2004, Marian POPESCU wrote: > Hi, > > I have a problem with this join query: > > > SELECT > CASE WHEN (UR.id_rights IS NULL) THEN '0' ELSE UR.id_rights END as > id_rights, > CASE WHEN (UR.r_category IS NULL) THEN 'CMP' ELSE UR.r_category END as > category, > U.id

[SQL] Join issue?

2004-12-15 Thread Marian POPESCU
Hi, I have a problem with this join query: SELECT CASE WHEN (UR.id_rights IS NULL) THEN '0' ELSE UR.id_rights END as id_rights, CASE WHEN (UR.r_category IS NULL) THEN 'CMP' ELSE UR.r_category END as category, U.id as id_user, U.username FROM mgw_users U LEFT OUTER J

Re: [SQL] Join issue on a maximum value

2004-04-26 Thread Jeremy Semeiks
On Wed, Apr 21, 2004 at 02:29:34PM -0400, Heflin wrote: > OK, it's been a while since I've had to do anything remotely complex in > SQL, so this may just be a pure brain block on my part. > ... > > So a basic JOIN gets this: > > SELECT auction.auction_id, image.image_id, image.image_descr > FROM

Re: [SQL] Join issue on a maximum value

2004-04-26 Thread Atesz
On Wed, Apr 21, 2004 at 14:29:34 -0400, Heflin wrote: > > SELECT auction.auction_id, image.image_id, image.image_descr FROM > auction JOIN image ON auction.auction_id = image.auction_id WHERE > auction.auction_owner = 'Mabel'; > In my opinion there are 2 problem: how can you make the query

Re: [SQL] Join issue on a maximum value

2004-04-22 Thread Tom Lane
Heflin <[EMAIL PROTECTED]> writes: > Bruno Wolff III wrote: >> The postgres specific way of doing this is: >> SELECT DISTINCT ON (auction.auction_id) >> auction.auction_id, image.image_id, image.image_descr >> FROM auction JOIN image ON auction.auction_id = image.auction_id >> WHERE auction.auction

Re: [SQL] Join issue on a maximum value

2004-04-21 Thread Bruno Wolff III
On Wed, Apr 21, 2004 at 16:28:10 -0400, Heflin <[EMAIL PROTECTED]> wrote: > > > >The postgres specific way of doing this is: > >SELECT DISTINCT ON (auction.auction_id) > > auction.auction_id, image.image_id, image.image_descr > > FROM auction JOIN image ON auction.auction_id = image.auction_id

Re: [SQL] Join issue on a maximum value

2004-04-21 Thread Edmund Bacon
Two choices that work: Either add another JOIN in which retrieves the MAX(image_id) for each auction: SELECT auction.auction_id, image.image_id, image.image_descr FROM auction JOIN image USING(auction_id) JOIN ( SELECT auction_id, MAX(image_id) AS image_id FROM image

Re: [SQL] Join issue on a maximum value

2004-04-21 Thread Bruno Wolff III
On Wed, Apr 21, 2004 at 14:29:34 -0400, Heflin <[EMAIL PROTECTED]> wrote: > > So a basic JOIN gets this: > > SELECT auction.auction_id, image.image_id, image.image_descr > FROM auction JOIN image ON auction.auction_id = image.auction_id > WHERE auction.auction_owner = 'Mabel'; > > Now the prob

Re: [SQL] Join issue on a maximum value

2004-04-21 Thread Heflin
Bruno Wolff III wrote: On Wed, Apr 21, 2004 at 14:29:34 -0400, Heflin <[EMAIL PROTECTED]> wrote: So a basic JOIN gets this: SELECT auction.auction_id, image.image_id, image.image_descr FROM auction JOIN image ON auction.auction_id = image.auction_id WHERE auction.auction_owner = 'Mabel'; Now

[SQL] Join issue on a maximum value

2004-04-21 Thread Heflin
OK, it's been a while since I've had to do anything remotely complex in SQL, so this may just be a pure brain block on my part. I have 2 tables, auction and image, defined like this: Table "public.auction" Column | Type |