Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Join using Like Condition

sliderrulesFeb 24 2015 — edited Feb 24 2015

Hi,

I would like to obtain the code from location_lookup table based on some descriptive text in the location_source table but this would require a join using a like condition. Also there are multiple location lookups with unique codes but the requirement would be to select the first code:

create table location_source
(code number,
description varchar2(100)
);

insert into location_source values('', 'check in london');
insert into location_source values('', 'flight Paris 9.30');
insert into location_source values('', 'baggage allowance 20kg Hong kong');
insert into location_source values('', 'check out 6.30');
insert into location_source values('', 'new york 23rd Jul');
insert into location_source values('', 'flight jy688 sydney');

create table location_lookup
(code number
location_lookup varchar2(10)
);

insert into location_lookup values (001, 'London');
insert into location_lookup values (002, 'London');
insert into location_lookup values (003, 'Paris');
insert into location_lookup values (004, 'Hong Kong');
insert into location_lookup values (005, 'Paris');
insert into location_lookup values (006, 'New York');

The SQL looks something like this:

select s.*, min(l.code) , l.location_lookup

from location_source s, locaction_lookup l

and UPPER(s.description||'%') like upper(l.location_lookup||'%')

group by s.*, l.location_lookup

Output Required:

CodeDescriptionCodeLocation_Lookup
check in london001London
flight Paris 9.30003Paris
baggage allowance 20kg Hong kong004Hong Kong
check out 6.30
new york 23rd Jul006New York
flight jy688 sydney
This post has been answered by Saubhik on Feb 24 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 24 2015
Added on Feb 24 2015
6 comments
12,224 views