Re: Joins on many-to-many relations.

Поиск
Список
Период
Сортировка
От Wiebe Cazemier
Тема Re: Joins on many-to-many relations.
Дата
Msg-id ete0ki$l9s$1@sea.gmane.org
обсуждение исходный текст
Ответ на Joins on many-to-many relations.  (Wiebe Cazemier <halfgaar@gmx.net>)
Список pgsql-sql
On Wednesday 14 March 2007 22:59, Wiebe Cazemier wrote:

> My question was mainly general;
> if there is a better way than using subselects to join two tables which
> are only connected to eachother through a join-table (containing only
> references to the two tables in question). Subselects are usually very
> slow, aren't they?

I fixed it. I now have a query with two outer joins, instead of the subselect
in the join condition:

SELECT DISTINCT ON (account.id) account.*
FROM trade.transaction_accounts AS account
INNER JOIN people.people AS owner       ON owner.id = account.owner_id
LEFT OUTER JOIN trade.transaction_account_co_owners acct_co_owner            ON account.id = acct_co_owner.account_id
LEFT OUTER JOIN people.people AS co_owner            ON acct_co_owner.co_owner_id = co_owner.id
WHERE upper(account.description) LIKE '%KOE%'
OR upper(owner.name) LIKE '%KOE%'
OR upper(owner.familiar_name) LIKE '%KOE%'
OR upper(owner.full_name) LIKE '%KOE%'
OR upper(co_owner.name) LIKE '%KOE%'
OR upper(co_owner.familiar_name) LIKE '%KOE%'
OR upper(co_owner.full_name) LIKE '%KOE%'

And now it executes in 1 ms.

This is what I was trying to do from the beginning, but because of some mental
block, was unable to think of the join condition...



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

Предыдущее
От: "Shavonne Marietta Wijesinghe"
Дата:
Сообщение: Re: INSERT INTO
Следующее
От: Guillaume Lelarge
Дата:
Сообщение: Re: INSERT INTO