Re: [SQL] "left join" not working?

2010-02-12 Thread Oliveiros C,
- Original Message - From: "Louis-David Mitterrand" To: Sent: Friday, February 12, 2010 11:57 AM Subject: Re: [SQL] "left join" not working? On Fri, Feb 12, 2010 at 11:35:02AM -, Oliveiros C, wrote: My first guess is that NULL fails the condition on your WHERE clause

Re: [SQL] "left join" not working?

2010-02-12 Thread Louis-David Mitterrand
On Fri, Feb 12, 2010 at 11:35:02AM -, Oliveiros C, wrote: > My first guess is that > NULL fails the condition on your WHERE clause, > p.id_line = 1 > > So your WHERE clause introduces an additional level of filtering > that filters out the NULLs coming from the LEFT JOIN... So, if I understan

Re: [SQL] "left join" not working?

2010-02-12 Thread msi77
> where p.id_line=1 this filters rows after join was applied. Try this select c.id_currency,max(p.modified_on) from currency c left join price_line p using (id_currency) where (p.id_line=1 or p.id_line is null) group by c.id_currency; > Hi, > This query: > select c.id_currency,max(p.modif

Re: [SQL] "left join" not working?

2010-02-12 Thread Oliveiros C,
al Message - From: "Louis-David Mitterrand" To: Sent: Friday, February 12, 2010 11:14 AM Subject: [SQL] "left join" not working? Hi, This query: select c.id_currency,max(p.modified_on) from currency c left join price_line p using (id_currency) where p.id_line=1 group by c.

[SQL] "left join" not working?

2010-02-12 Thread Louis-David Mitterrand
Hi, This query: select c.id_currency,max(p.modified_on) from currency c left join price_line p using (id_currency) where p.id_line=1 group by c.id_currency; doesn't list all c.id_currency's, only those with a price_line. However this one does: select c.id_currency,max(p.modified_on) from curren

Re: [SQL] left join where not null vs. inner join

2009-05-22 Thread Erik Jones
On May 22, 2009, at 1:51 PM, Emi Lu wrote: Two tables, each contains more than hundreds of thousands records. Is there any efficiency differences between (1) and (2)? (1) T1 inner join T2 using (c1, c2) (2) T1 left join T2 using (c1, c2) where c2 is not null Yes, stick with the first. I

[SQL] left join where not null vs. inner join

2009-05-22 Thread Emi Lu
Two tables, each contains more than hundreds of thousands records. Is there any efficiency differences between (1) and (2)? (1) T1 inner join T2 using (c1, c2) (2) T1 left join T2 using (c1, c2) where c2 is not null Thanks, -- Lu Ying -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql

Re: [SQL] Left Join Question

2008-11-19 Thread Ryan Wells
Thanks for the feedback, everyone. > > FROM tasks > > LEFT JOIN clients ON tasks.ClientId = clients.ClientId > > LEFT JOIN iteminfo ON tasks.Id = iteminfo.ItemId > >LEFT JOIN changelog ON tasks.Id = changelog.ItemId > > LEFT JOIN ticklers ON tasks.Id = ticklers.RelatedId > > WHERE

Re: [SQL] Left Join Question

2008-11-18 Thread Richard Huxton
Ryan Wells wrote: > > FROM tasks > LEFT JOIN clients ON tasks.ClientId = clients.ClientId > LEFT JOIN iteminfo ON tasks.Id = iteminfo.ItemId >LEFT JOIN changelog ON tasks.Id = changelog.ItemId > LEFT JOIN ticklers ON tasks.Id = ticklers.RelatedId > WHERE tasks.Id = '123456'; > > (

Re: [SQL] Left Join Question

2008-11-18 Thread Mark Roberts
On Tue, 2008-11-18 at 16:48 -0600, Ryan Wells wrote: > Since it works, my question is really more about principles: Given > that each of the tables in question will contain tens of thousands of > rows, is a nested join really the best way to approach this? I don't see what's wrong with it. The

Re: [SQL] Left Join Question

2008-11-18 Thread ries van Twisk
On Nov 18, 2008, at 5:48 PM, Ryan Wells wrote: While looking through our data layer code today, I ran across this query: SELECT tasks.*, clients.FirstName, clients.LastName, clients.MiddleInitial, iteminfo.CreatedBy, iteminfo.StationId, iteminfo.CreatedDate, changelog.LastModified, changelog

[SQL] Left Join Question

2008-11-18 Thread Ryan Wells
While looking through our data layer code today, I ran across this query: SELECT tasks.*, clients.FirstName, clients.LastName, clients.MiddleInitial, iteminfo.CreatedBy, iteminfo.StationId, iteminfo.CreatedDate, changelog.LastModified, changelog.LastModifiedBy, changelog.LastModified

Re: [SQL] LEFT Join Question

2007-01-26 Thread Rob V
Thanks codeWarrior - you got me 99% there - I just needed to add the NULL "trick" on the join w/ the contact_phone and contact_address tables and that got me the results I was after! This is what I the final qry looks like : SELECT A.account_id, A.account_username, V.vendor_contract_signed_date,

Re: [SQL] LEFT Join Question

2007-01-26 Thread Andrew Sullivan
On Thu, Jan 25, 2007 at 06:51:34PM -0500, Rob V wrote: > > I know I have to use a left join - but I can seem to figure out the syntax > when dealing w/ different columns of the same table. I haven't tested this to remind myself for sure that it will work, but I think you ought to be able to RIGHT

Re: [SQL] LEFT Join Question

2007-01-25 Thread codeWarrior
Fisrt -- you probably want to start by doing fully qualified JOINS and then you want to allow joins with nulls on the columns that are allowed to be empty: I am doing this sort of off the top of my head ... but the thing you need to do generally is to COMPLETELY QUALIFY all of your joins and the

Re: [SQL] LEFT Join Question

2007-01-25 Thread Rob V
Just 1 followup to this : they MAY or MAYNOT have records in the following tables : contact_address,contact_phone There may also be multiple records in that table w/ the same account_id - but the domain_type_id will be different. so the contact_phone could have 2 records : account_id 1, domain PR

[SQL] LEFT Join Question

2007-01-25 Thread Rob V
Hello all, Ive been racking my brain for a few hours now and need some help, please!!! I have the following tables : account =account_id =account_type_id =account_username vendor =account_id =vendor_status contact_name =account_id =name =domain_type_id contact_address =account_id =address =d

RES: [SQL] Left join?

2006-07-02 Thread Carlos H. Reimer
It´s just want I need! Perfect! Thanks! Carlos > -Mensagem original- > De: Richard Broersma Jr [mailto:[EMAIL PROTECTED] > Enviada em: sábado, 1 de julho de 2006 18:45 > Para: [EMAIL PROTECTED]; pgsql-sql@postgresql.org > Assunto: Re: [SQL] Left join? > > >

Re: [SQL] Left join?

2006-07-01 Thread Richard Broersma Jr
> In the following table, codsol, codate and codfec are foreign keys > referencing table func and I need some help to codify a SELECT command that > produces the following result set but instead of codsol, codate and codfec I > need the respectives names (column nome from table func). > > postgre

[SQL] Left join?

2006-07-01 Thread Carlos H. Reimer
Hi, In the following table, codsol, codate and codfec are foreign keys referencing table func and I need some help to codify a SELECT command that produces the following result set but instead of codsol, codate and codfec I need the respectives names (column nome from table func). postgres=# sel

[SQL] Left join pa on dal resulting in null

2005-08-12 Thread Ilene
Greetings, I have the following join, and in this join I am getting all of the data except that which joins the pa table to the dao table. When I try to join it using a left join, i get all of the data except this table. When I use a right join, I get nothing at all. If I make this a s

Re: [SQL] left join on a view takes significantly more time.

2004-03-31 Thread Josh Berkus
Manuel, > I'm facing a wired problem. When I left join two tables PostgreSQL is > able to do it fast using the corresponding indices, However, if I > define a simple view (to format the data) on one of the tables, the > left join does not use the indices. Is something wrong here? At a guess, the

[SQL] left join on a view takes significantly more time.

2004-03-31 Thread Manuel Sugawara
Hi, I'm facing a wired problem. When I left join two tables PostgreSQL is able to do it fast using the corresponding indices, However, if I define a simple view (to format the data) on one of the tables, the left join does not use the indices. Is something wrong here? The two tables: ***

Re: [SQL] LEFT JOIN on one and/or another column (thanks)

2004-01-29 Thread Octavio Alvarez
Yes, Bruno. Thank you very much. That's what I was looking for, but since I hadn't used CASE nor COALESCE, I didn't know it was easier that way. The idea is that on a column I have info about a routine task, and in another one I have info about human-made changes to the time of that task, like as

Re: [SQL] LEFT JOIN on one and/or another column

2004-01-29 Thread Bruno Wolff III
On Wed, Jan 28, 2004 at 20:27:00 -0800, Octavio Alvarez <[EMAIL PROTECTED]> wrote: > > Hi. I have a table with two foreign keys (1 field each), like in > > id| serial > ext_key_original | integer > ext_key_exception | integer > > They mean different things, as one refers to

[SQL] LEFT JOIN on one and/or another column

2004-01-28 Thread Octavio Alvarez
Hi. I have a table with two foreign keys (1 field each), like in id| serial ext_key_original | integer ext_key_exception | integer They mean different things, as one refers to a typical value, and the other one refers to an exception that applies for that tuple. Each key ref

Re: [SQL] left join in cursor

2003-06-10 Thread Tom Lane
Alexey Dashevsky <[EMAIL PROTECTED]> writes: > DECLARE "c" SCROLL CURSOR FOR select a.*,r.b1 as rb1 from a left join b using > (cl) order by a.cl; > FETCH FORWARD 100 in "c"; > FETCH FORWARD 100 in "c"; > MOVE -200 in "c"; > [ core dump ] Some plan node types don't cope very well with being run b

[SQL] left join in cursor

2003-06-10 Thread Alexey Dashevsky
Hi. Exists too tables (PostgreSQL 7.2.3): a ("cl" integer primary key, a1, a2, ...) - 10 records; b ("cl" integer primary key, b1, b2, ...) - 800 records. BEGIN; DECLARE "c" SCROLL CURSOR FOR select a.*,r.b1 as rb1 from a left join b using (cl) order by a.cl; FETCH FORWARD 100 in "c";

Re: [SQL] LEFT JOIN and missing values

2003-03-12 Thread mila
Tomasz, > select c.id1, d.id1, sum( > case when c.id2 is null then 0.5 else c.val2 end * > case when d.id2 is null then 0.5 else d.val2 end *T1.val1) > from > T1 > left join T2 c on (c.ID2 = T1.id) > left join T2 d on (d.id2 = T1.id and (c.id1 < d.id1 or c.id1 is null)) > group by c.id1,

Re: [SQL] left join query does not perform well

2002-08-25 Thread Tom Lane
Manuel Sugawara <[EMAIL PROTECTED]> writes: > Ouch, 3117.48 msec vs. 1.15 msec is a huge difference. I need > something else? or may be postgres optimizer can't cope with > left/right joins? I think the problem is you're constraining the join order into a very inefficient one. See http://www.ca

[SQL] left join query does not perform well

2002-08-24 Thread Manuel Sugawara
Hi all, I have three tables that are related in the following way: ' | epr_ord_grupo < 1 - n > epr_ord_profesor < 0 - n > epr_ord_horario ` In average there is 1.0407716514 rows in epr_ord_horario for each row in e

Re: [SQL] LEFT JOIN ...

2001-06-18 Thread The Hermit Hacker
Perfect, thank you ... i knew I was overlooking something obvious ... the query just flies now ... On Mon, 18 Jun 2001, Tom Lane wrote: > The Hermit Hacker <[EMAIL PROTECTED]> writes: > >> Try adding ... AND n.nid = 15748 ... to the WHERE. > > > n.nid is the note id ... nl.id is the contact id

Re: [SQL] LEFT JOIN ...

2001-06-18 Thread Tom Lane
The Hermit Hacker <[EMAIL PROTECTED]> writes: >> Try adding ... AND n.nid = 15748 ... to the WHERE. > n.nid is the note id ... nl.id is the contact id ... Ooops, I misread "n.nid = nl.nid" as "n.nid = nl.id". Sorry for the bogus advice. Try rephrasing as FROM (note_links nl JOIN notes n ON (

Re: [SQL] LEFT JOIN ...

2001-06-18 Thread Stephan Szabo
I think that using INNER JOIN between nl and n (on n.nid=nl.nid) or joining those tables in a subquery might work. On Mon, 18 Jun 2001, The Hermit Hacker wrote: > Is there some way to write the above so that it evaluates: > > WHERE (n.type = 'A' OR n.type = 'N' OR n.type = 'H' OR n.ty

Re: [SQL] LEFT JOIN ...

2001-06-18 Thread The Hermit Hacker
On Mon, 18 Jun 2001, Tom Lane wrote: > The Hermit Hacker <[EMAIL PROTECTED]> writes: > > FROM note_links nl, notes n LEFT JOIN calendar c ON (n.nid = c.nid) > > WHERE (n.type = 'A' OR n.type = 'N' OR n.type = 'H' OR n.type = 'C') > > AND (nl.id = 15748 AND contact_lvl = 'c

Re: [SQL] LEFT JOIN ...

2001-06-18 Thread Tom Lane
The Hermit Hacker <[EMAIL PROTECTED]> writes: > FROM note_links nl, notes n LEFT JOIN calendar c ON (n.nid = c.nid) > WHERE (n.type = 'A' OR n.type = 'N' OR n.type = 'H' OR n.type = 'C') > AND (nl.id = 15748 AND contact_lvl = 'company') > AND n.nid = nl.nid >

[SQL] LEFT JOIN ...

2001-06-18 Thread The Hermit Hacker
Morning ... I'm trying to wrack my brain over something here, and no matter how I try and look at it, I'm drawing a blank ... I have two tables that are dependent on each other: notes (86736 tuples) and note_links (173473 tuples) The relationship is that one no

Re: [SQL] left join syntax

2001-05-08 Thread Oliver Elphick
"Haywood J'Bleauxmie" wrote: >I have a database that tracks work orders. Each order tracks two entries >from the employees table; the employee ID of the person assigned to the >work order and the ID of the person who completed the order. Each work >order may have one, both, or neither f

[SQL] left join syntax

2001-05-08 Thread Haywood J'Bleauxmie
I have a database that tracks work orders. Each order tracks two entries from the employees table; the employee ID of the person assigned to the work order and the ID of the person who completed the order. Each work order may have one, both, or neither field filled in. As such, I need to left

[SQL] LEFT JOIN

2001-03-21 Thread Grant Furick
I am trying to output news. An article can have an image or not sometimes. Can someone help me get this to work in Postgres? select a.article_id, a.title, a.url, a.synopsis, a.publish_date, c.parent_category_id, c.category_id, c.category_name, i.server_image_name from ((article a JOIN articl

[SQL] left join ?

2000-12-29 Thread xyzii
hi all, I try select purc.trn_no,purcsub.item_no,purcsub.qty,emp_no,emp_na from purc left join purcsub on (purc.trn_no=purcsub.trn_no) left join emp on (purc.emp_no = emp.emp_no) postgresql not run,please help,thank

Re: Antw: [SQL] LEFT JOIN

2000-07-04 Thread Tom Lane
Antti Linno <[EMAIL PROTECTED]> writes: >> I think, the following select will solve your problem >> >> select first.id >> from first >> except >> second.id_first >> from second; >> > Nay, I got parse error. Should be ... EXCEPT SELECT second.id_first ... Anyway, we should have full ANSI join

ODP: Antw: [SQL] LEFT JOIN

2000-07-04 Thread Rybarczyk Mikolaj
Try this: > Nay, I got parse error. > Antti select first.id from first except select second.id_first from second; Greetings, Mikolaj.

Re: Antw: [SQL] LEFT JOIN

2000-07-04 Thread Erol Oz
Antti Linno wrote: > > > I think, the following select will solve your problem > > > > select first.id > > from first > > except > > second.id_first > > from second; > > > Nay, I got parse error. 'select' is missing after 'except'. select first.id from first except select second.id_firs

Re: Antw: [SQL] LEFT JOIN

2000-07-04 Thread Antti Linno
> I think, the following select will solve your problem > > select first.id > from first > except > second.id_first > from second; > Nay, I got parse error. Antti

Antw: [SQL] LEFT JOIN

2000-07-04 Thread Gerhard Dieringer
Antti Linno wrote: > Greetings. > I have a problem. I have 2 tables. E.g. work and workers. I want to > select records, that 1st table has, and the second hasn't(both have id > attribute). I mean I can't do it with is NULL, because those records don't > exist. I was shown, how it is done with my

[SQL] LEFT JOIN

2000-07-04 Thread Antti Linno
Greetings. I have a problem. I have 2 tables. E.g. work and workers. I want to select records, that 1st table has, and the second hasn't(both have id attribute). I mean I can't do it with is NULL, because those records don't exist. I was shown, how it is done with mysql select first.id,second.id