Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > Oracle > Joining with LIKE?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-27-08, 12:41
Tarkon Tarkon is offline
Registered User
 
Join Date: Sep 2003
Location: Washington, DC - USA
Posts: 30
Question Joining with LIKE?

Hi,

I have two tables that I need to join together for a query - the problem is that in one table the column MAY have a leading zero (if it's 4 characters long), and the other table will never have a leading zero.

An example:
Code:
Table1 Table2 ---------------------- 04232 | 4232 50292 | 50292 03211 | 3211 06843 | 6843

I was thinking of doing something along the lines of

LEFT JOIN Table2 ON
Table2.Column1 LIKE %Table1.Column1

But I don't think that's possible. Could anyone help me out?

Thanks!
-T
Reply With Quote
  #2 (permalink)  
Old 06-27-08, 13:20
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 3,563
what are the datatype for the two columns?
it appear you are storing numbers in a VARCHAR2 field in Table1
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
Reply With Quote
  #3 (permalink)  
Old 06-27-08, 15:07
Tarkon Tarkon is offline
Registered User
 
Join Date: Sep 2003
Location: Washington, DC - USA
Posts: 30
It's VARCHAR2 since sometimes they're alphanumeric.

Quote:
Originally Posted by anacedent
what are the datatype for the two columns?
it appear you are storing numbers in a VARCHAR2 field in Table1
Reply With Quote
  #4 (permalink)  
Old 06-27-08, 16:42
AlanP AlanP is offline
Registered User
 
Join Date: Mar 2002
Location: Reading, UK
Posts: 1,098
Yep you can use like for a join i.e.

select *
from a, b
where a.col1 like '%'||b.col2

Alan
Reply With Quote
  #5 (permalink)  
Old 06-27-08, 17:36
beilstwh beilstwh is offline
Registered User
 
Join Date: Jun 2004
Location: Liverpool, NY USA
Posts: 1,642
or if the leading zero the only issue

select *
from a, b
where a.col1 = ltrim(b.col2,'0');
__________________
Bill
Cream always raises to the top, and so does the scum!!
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

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