RE: ambiguous

From: "Tamsin" <tg_mail(at)bryncadfan(dot)co(dot)uk>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: RE: ambiguous
Date: 2001-03-07 15:46:15
Message-ID: NEBBKHBOBMJCHDMGKCNJOEMDCKAA.tg_mail@bryncadfan.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

You need to qualify which dept_id you are refering to in your where clause:

select * from department, employee where department.dept_no = '1';

Also, unless you join the two tables in your where clause you'll get a
cartesian join, so you might want to do:

select * from department, employee
where department.dept_no = '1' and department.dept_no = employee.dept_no;

You can also use aliases for your tablenames to save typing:

select * from department d, employee e
where d.dept_no = '1' and d.dept_no = e.dept_no;

Hope this helps,
Tamsin

> -----Original Message-----
> From: pgsql-novice-owner(at)postgresql(dot)org
> [mailto:pgsql-novice-owner(at)postgresql(dot)org]On Behalf Of si
> Sent: 07 March 2001 15:33
> To: pgsql-novice(at)postgresql(dot)org
> Subject: [NOVICE] ambiguous
>
>
> If I assign the same name to 2 columns in 2 different tables:
>
> +--------------------------------------+
> | DEPARTMENT |
> +----------+----------------+----------+
> | LOCATION | DESCRIPTION | DEPT_NO |
> +----------+----------------+----------+
> | Bedrock | Administration | 1 |
> +----------+----------------+----------+
>
> +--------------------------------+
> | EMPLOYEE |
> +---------+------------+---------+
> | EMPL_ID | NAME_LAST | DEPT_NO |
> +---------+------------+---------+
> | 1 | Slate | 1 |
> +---------+------------+---------+
>
> select * from DEPARTMENT, Employee where dept_no = '1';
>
> PG throws up:
> ERROR: Column 'dept_no' is ambiguous
>
> Is this not allowed? or is my sql understanding wrong?
>
>
> _____________________________________________________________
> Pick up your email anywhere in the world ---> http://www.remail.net
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Roland Roberts 2001-03-07 20:40:44 Re: [SQL] Permissons on database
Previous Message si 2001-03-07 15:33:19 ambiguous