Re: joining a query with a select count(*)

Поиск
Список
Период
Сортировка
От Martijn van Oosterhout
Тема Re: joining a query with a select count(*)
Дата
Msg-id 20051105184725.GB6828@svana.org
обсуждение исходный текст
Ответ на joining a query with a select count(*)  (Matthew Terenzio <matt@jobsforge.com>)
Список pgsql-general
On Sat, Nov 05, 2005 at 01:10:13PM -0500, Matthew Terenzio wrote:
>
> I want a query to return all the rows from one table along with a count
> of rows in another table that reference each returned row from the
> first table.

Quick and dirty, should give you the idea...

select *, (select count(*) from table2 where fkey=pkey) from table1;

Hope this helps,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Вложения

В списке pgsql-general по дате отправления:

Предыдущее
От: Matthew Terenzio
Дата:
Сообщение: joining a query with a select count(*)
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Missing variable "role" in "pg_settings"?