Re: SQL Syntax / Logic question - Mailing list pgsql-sql

From Josh Berkus
Subject Re: SQL Syntax / Logic question
Date
Msg-id web-141646@davinci.ethosmedia.com
Whole thread Raw
In response to SQL Syntax / Logic question  ("Michael D. Harlan" <r3mdh@beechwoodplace.org>)
List 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@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco

Attachment

pgsql-sql by date:

Previous
From: Karel Zak
Date:
Subject: Re: to_date/to timestamp going to BC
Next
From: Tomasz Myrta
Date:
Subject: temporary views