Re: where clauses and multiple tables
От | Yaroslav Tykhiy |
---|---|
Тема | Re: where clauses and multiple tables |
Дата | |
Msg-id | 0D71ADA4-41CE-446A-8F0E-5E8F590E9224@barnet.com.au обсуждение исходный текст |
Ответ на | Re: where clauses and multiple tables (David W Noon <dwnoon@ntlworld.com>) |
Ответы |
Re: where clauses and multiple tables
|
Список | pgsql-general |
On 09/09/2009, at 9:02 AM, David W Noon wrote: > On Tue, 8 Sep 2009 14:25:20 -0700, Scott Frankel wrote about [GENERAL] > where clauses and multiple tables: > >> Is it possible to join tables in the where clause of a statement? > [snip] >> Given a statement as follows: >> >> SELECT foo.foo_id, foo.name >> FROM foo, bar >> WHERE foo.bar_id = bar.bar_id >> AND bar.name = 'martini'; > > Just use an IN predicate: > > SELECT foo_id, name FROM foo > WHERE bar_id IN (SELECT bar_id FROM bar WHERE name = 'martini'); > > This is frequently called a semi-join. By the way, folks, do you think there may be performance gain or loss from rewriting this with an explicit JOIN? E.g.: SELECT DISTINCT foo.foo_id, foo.name FROM foo JOIN bar ON foo.bar_id = bar.bar_id WHERE bar.name='martini'; Thanks! Yar
В списке pgsql-general по дате отправления: