Left Join Question - Mailing list pgsql-sql

From Ryan Wells
Subject Left Join Question
Date
Msg-id 52F2AD70C422474B857FC9E3F7B62539028DB1E8@exchange.DOCS.COM
Whole thread Raw
Responses Re: Left Join Question
Re: Left Join Question
Re: Left Join Question
List pgsql-sql
<div class="Section1"><p class="MsoNormal">While looking through our data layer code today, I ran across this query:<p
class="MsoNormal"> <pclass="MsoNormal">SELECT <p class="MsoNormal">tasks.*,<p class="MsoNormal">clients.FirstName,<p
class="MsoNormal">clients.LastName,<pclass="MsoNormal">clients.MiddleInitial,<p class="MsoNormal">iteminfo.CreatedBy,<p
class="MsoNormal">iteminfo.StationId,<pclass="MsoNormal">iteminfo.CreatedDate,<p
class="MsoNormal">changelog.LastModified,<pclass="MsoNormal">changelog.LastModifiedBy,<p
class="MsoNormal">changelog.LastModifiedAt,<pclass="MsoNormal">ticklers.Due,<p class="MsoNormal">ticklers.Reminder<p
class="MsoNormal"> <pclass="MsoNormal">FROM tasks <p class="MsoNormal"> LEFT JOIN clients ON tasks.ClientId =
clients.ClientId<p class="MsoNormal">  LEFT JOIN iteminfo ON tasks.Id = iteminfo.ItemId <p class="MsoNormal">   LEFT
JOINchangelog ON tasks.Id = changelog.ItemId <p class="MsoNormal">    LEFT JOIN ticklers ON tasks.Id =
ticklers.RelatedId<p class="MsoNormal"> <p class="MsoNormal">WHERE tasks.Id = '123456';<p class="MsoNormal"> <p
class="MsoNormal">(I'vecleaned it up so it's  easier to read.)<p class="MsoNormal"> <p class="MsoNormal">The basic data
structureis that we have a todo list that contains a list of tasks which may or may not be associated with clients,
items,log entries, or ticklers (scheduled reminders).  <p class="MsoNormal"> <p class="MsoNormal">The query works as
intended: it returns a result-set with all the necessary data to display in the todo list.   The performance is not a
majorconcern, although it can be slow for large lists.<p class="MsoNormal"> <p class="MsoNormal">Since it works, my
questionis 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?<p class="MsoNormal"> <p class="MsoNormal">Thanks!<p
class="MsoNormal">Ryan</div>

pgsql-sql by date:

Previous
From: Gerardo Herzig
Date:
Subject: Re: custom serial number
Next
From: ries van Twisk
Date:
Subject: Re: Left Join Question