If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > select with wildcards

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-02-04, 12:26
yarivvv yarivvv is offline
Registered User
 
Join Date: Mar 2004
Posts: 2
Question select with wildcards

Hi,

I'm trying to write a SELECT query (in Oracle) that mimics a join of two tables. However, instead of matching values exactly, it looks for values of one table that are substrings of another table's column's values.

Basically, I envision the query to have the following form:

SELECT a.name1, b.name2
FROM a, b
WHERE name1 like %name2%

The problem is that the '%' symbols cause Oracle to throw an error.

If you know of another way of writing such a query, please let me know!

Thanks in advance,
Yariv
Reply With Quote
  #2 (permalink)  
Old 03-02-04, 13:34
ss659 ss659 is offline
Registered User
 
Join Date: Jan 2004
Posts: 492
Re: select with wildcards

Quote:
Originally posted by yarivvv
Hi,

I'm trying to write a SELECT query (in Oracle) that mimics a join of two tables. However, instead of matching values exactly, it looks for values of one table that are substrings of another table's column's values.

Basically, I envision the query to have the following form:

SELECT a.name1, b.name2
FROM a, b
WHERE name1 like %name2%

The problem is that the '%' symbols cause Oracle to throw an error.

If you know of another way of writing such a query, please let me know!

Thanks in advance,
Yariv

Not sure if you know the substring sections but you could do something like:

Code:
SELECT
a.name1, b.name2
from a,b
where a.name1 = substr(b.name2, 1, 10)
Reply With Quote
  #3 (permalink)  
Old 03-02-04, 16:12
yarivvv yarivvv is offline
Registered User
 
Join Date: Mar 2004
Posts: 2
thanks!
Reply With Quote
  #4 (permalink)  
Old 03-02-04, 22:55
r123456 r123456 is offline
Registered User
 
Join Date: Sep 2003
Location: The extremely Royal borough of Kensington, London
Posts: 778
select *
from
tableA a
INNER JOIN
tableB b ON
a.name LIKE '%'||b.name||'%';
__________________
Bessie Braddock: Winston, you are drunk!
Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On