Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Help with multi-table partial select

Help with multi-table partial select

From: <danb5_at_my-dejanews.com>
Date: Tue, 21 Jul 1998 16:32:24 GMT
Message-ID: <6p2fqo$og5$1@nnrp1.dejanews.com>


I am trying to formulate a query involving two tables, and I'm not having much luck.

The schema: One table is "family" while the other is "person". Each person has a foreign key to a family. For instance, Let's say ID 42 is assigned to family "Clinton" and you have person "Bill" which holds the foreign key 42 to the Clinton family.

What I'm trying to do is to formulate a query to choose one and only one person per family. (It doesn't particularly matter which one; perhaps the first one found according to sort order). The closest I can get is this query to choose _every_ family member:

select p.id, f.id, p.firstname, f.name
from person p, family f
where f.id=p.familyid
order by f.name

I know I could just use this select statement and programatically throw away extraneous family members, but I really need to do this in one query. Perhaps a nested select or some such?

So far, all my SQL-knowledgeable friends are stumped. Any ideas? TIA.

-----== Posted via Deja News, The Leader in Internet Discussion ==----- http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum Received on Tue Jul 21 1998 - 11:32:24 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US