Re: [SQL] 2 Table Select

From: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
To: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] 2 Table Select
Date: 1999-05-30 11:24:54
Message-ID: l03130301b376cff230ad@[147.233.159.109]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

At 22:34 +0300 on 27/05/1999, Oliver Elphick wrote:

>
> select c.company_id, count(j.job_id)
> from company as c, jobs as j
> where c.company_id = j.company_id
> group by c.company_id;

If it's only the company_id that interests you, and not the company name or
other details in the company table, you can give up the company table
altogether. The company_id appears in the jobs table, and there is no point
in selecting c.company_id when the condition was that c.company_id is equal
to j.company_id.

In other words, if all you need is company_id, you can use:

select company_id, count(job_id)
from jobs
group by company_id;

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Herouth Maoz 1999-05-30 13:13:46 Re: [SQL] Does PostgreSQL have an UPDATE Function like UNIFY?
Previous Message Tom Lane 1999-05-29 14:54:39 Re: [SQL] Does PostgreSQL have an UPDATE Function like UNIFY?