Skip site navigation (1) Skip section navigation (2)

join if there, blank if not

From: Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk>
To: "'pgsql-sql(at)postgresql(dot)org'" <pgsql-sql(at)postgresql(dot)org>
Subject: join if there, blank if not
Date: 2000-07-12 15:34:04
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
Hi all,

I just can't get my head round this one so I hope one of you can.

I've got two tables, one holding phone calls, and another holding phone numbers.

I want to do a select where if the number in the calls table exists 
in the numbers table, the description is included otherwise the 
description field is blank.

Unfortunately, using the select I've tried, if the number is not on 
the one of the tables, it's ignored.

Calls table
cdate date
ctime time
cextn char(3)
cnumber x(12)

Numbers table

nnumber x(12)
ndesc x(30)

Select I tried.

select c.cdate, c.ctime, c.cextn, c.cnumber n.ndesc 
from calls c, numbers n where c.cnumber = n.nnumber;

Gary Stainburn.
Work: mailto:gary(dot)stainburn(at)ringways(dot)co(dot)uk
REVCOM: mailto:gary(dot)stainburn(at)revcom(dot)org(dot)uk
Murphy's Laws: (327) The minute before the engineer arrives, the printer starts working.


pgsql-sql by date

Next:From: Brian PowellDate: 2000-07-12 16:24:36
Subject: Bug in to_char()
Previous:From: Jacques WilliamsDate: 2000-07-12 14:41:12
Subject: Re: join if there, blank if not

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group