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

Home -> Community -> Usenet -> c.d.o.server -> sql return only first matching record from join table

sql return only first matching record from join table

From: Barnoit <jbarney_ca_at_yahoo.ca>
Date: 3 Jul 2002 07:00:26 -0700
Message-ID: <cd2c60c8.0207030600.39d024b8@posting.google.com>


Just to simplify my example, I have 2 tables that are joined on a key id (there are actually quite a few joins, but this is the one causing me trouble). The keyid on the first table is unique, but there is a one to many relationship in the second table (it is actually a street address table and an occupant table). What I need to be able to do is to a select using the keyid as the join criteria, but I only want to return the first matching record and disregard any other matches. So just to reconfirm, I want to do a select based on an address, join based on the keyid and return the name of the first person that it finds, disregarding any other occupants it finds. Any suggestions would be greatly appreciated.
ex.
select table1.address, table2.name
from table1, table2
where address = '123 Main St'
and table1.keyid = table2.keyid

What I am getting is
123 Main St, Joe Blow
123 Main St, John Q. Public ...

but what I really want is whatever the first match is. I can't use pl/sql in this case, has to be sql only. I'm hoping I'm just overlooking something very simple, and BTW this is on oracle 8.0.5 Received on Wed Jul 03 2002 - 09:00:26 CDT

Original text of this message

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