pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: angelko@saw.net
To: pgsql-sql@postgresql.org
Subject: [Q] Merging two queries?
Date: Sat, 18 Dec 1999 15:00:18 -0800 (PST)
Message-ID: <Pine.LNX.3.96.991218145643.29025E-100000@brook.saw.net> (raw)

Hello,

I'm working on a query that confuses me. This is a database of vehicles,
and dealers. four tables are involved.

Dealership, UsedCar, Members, Ads

Dealership contains the information about various car dealerships.
UsedCar contains the information about the cars those dealerships sell.

Members is similar to Dealership, except it is for car owners who
are sellilng their own vehicle. Each owner from Members has one or
more entries in Ads table. Ads table contains the information about
the used cars that members want to sell.

Here is a sample query involving Dealership and UsedCar

SELECT DISTINCT UsedCar.Make, UsedCar.Model
FROM  Dealership,  UsedCar
WHERE Dealership.DealerID = UsedCar.DealerID
      AND Dealership.States Like '%Oregon%'

And the sample output is:

Pontiac  |Grand prix se sedan 4d
Pontiac  |Sunfire se sedan 4d
Saturn   |Sc1 coupe 2d
Saturn   |Sc2 coupe 2d


Here is another query involving Members and Ads

SELECT DISTINCT Ads.Make, Ads.Model
FROM  Members,  Ads
WHERE Members.Member_ID = Ads.Member_ID
      AND Members.Addr_State = 'OR'

And the sample output is:

Pontiac  |Sunfire se sedan 2d
Saturn   |Sc2 coupe 4d


I would like to create a single query that will generate output like:

Pontiac  |Grand prix se sedan 4d
Pontiac  |Sunfire se sedan 2d
Pontiac  |Sunfire se sedan 4d
Saturn   |Sc1 coupe 2d
Saturn   |Sc2 coupe 2d
Saturn   |Sc2 coupe 4d


Anyone has any suggestions?

Thanks,

-angelko




view thread (2+ messages)

Message-ID: <Pine.LNX.3.96.991218145643.29025E-100000@brook.saw.net>
Permalink:  ../Pine.LNX.3.96.991218145643.29025E-100000@brook.saw.net/
Also on:    postgresql.org/message-id/Pine.LNX.3.96.991218145643.29025E-100000@brook.saw.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: angelko@saw.net
  Subject: Re: [Q] Merging two queries?
  In-Reply-To: <Pine.LNX.3.96.991218145643.29025E-100000@brook.saw.net>
  References: <Pine.LNX.3.96.991218145643.29025E-100000@brook.saw.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox