Re: Advanced SQL

  • From: Dorene Cornwell <dorenefc@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Thu, 25 Aug 2011 20:51:44 -0700

Hi Jeff

It looks to me like the relationship table has already done whatever
you need to add information from the Action table.  Have I read that
correctly?

In that case, all you need to do is left join the topic table on topic
id to add whatever you need from the topic table. Then the topics
where there is nothing in the relationship table that matches by topic
id will show up with the topic and the action id missing. That is what
you want.

The exact syntax depends on what flavor of SQL you are working with.
It looks to me like

Have I misunderstood what you need to do?

DoreneC
Seattle WA

On 8/25/11, Jeff Berwick <mailinglists@xxxxxxxxxxxx> wrote:
> Hi Listers,
>
> I need some sql assistance.
>
> I have three tables that are connected in a many to many relationship.  The
> three tables are:
>
> topic, relationship (the many to many table) and Action.
>
> I want to show all the relationships but, if there are no relationships I
> need to still show the Topics.  Sample tables might look like:
>
> Topic
>  ++++++
> id
> +++++
> 1
> 2
> 3
> 4
>
> Relationship
> +++++++
> topic_id | action_id
> +++++++
> 1 | 1
> 3 | 2
> 4 | 3
> 4 | 4
>
> Action
> ++++++
> id
> +++++
> 1
> 2
> 3
> 4
>
> I know I need to use a left outer join at some point but, can't get this
> figured out.  Any assistance is welcome and appreciated.
>
> TIA,
> Jeff
>
> __________
> View the list's information and change your settings at
> //www.freelists.org/list/programmingblind
>
>
__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: