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