Re: SQL Syntax / Logic question

From: "Josh Berkus" <josh(at)agliodbs(dot)com>
To: "Michael D(dot) Harlan" <r3mdh(at)beechwoodplace(dot)org>, pgsql-sql(at)postgresql(dot)org
Subject: Re: SQL Syntax / Logic question
Date: 2001-10-04 15:02:00
Message-ID: web-141646@davinci.ethosmedia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Mike,

> select frienda, friendb from friends where (select
> schools.school from friends,schools where friends.frienda =
> schools.person) = (select schools.school from friends,schools where
> friends.friendb = schools.person);

Too complicated. You need to learn how to use JOINS and table aliases
(or find yourself some friends who know SQL!):

SELECT friends.frienda, friends.friendb
FROM friends JOIN schools schoola ON friends.frienda = schoola.person
JOIN schools schoolb ON friends.friendb = schoolb.person
WHERE schoola.school = schoolb.school

and, if it's possible that any particular person went to more than one
school, add:

GROUP BY frienda, friendb

Simple, neh?

-Josh

______AGLIO DATABASE SOLUTIONS___________________________
Josh Berkus
Complete information technology josh(at)agliodbs(dot)com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco

Attachment Content-Type Size
unknown_filename text/plain 2 bytes
unknown_filename text/plain 2 bytes
unknown_filename text/plain 2 bytes

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Marat Khairullin 2001-10-04 15:08:29 Why the weak key is created as unique
Previous Message Karel Zak 2001-10-04 14:56:06 Re: to_date/to timestamp going to BC