Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Like need help

Status
Not open for further replies.

CassidyHunt

IS-IT--Management
Jan 7, 2004
688
US
Basically I have two tables:

Code:
Test    Result
-----------------------
abcdB   3316
bcdaB   3345
abcd    3316

Code:
Test
-----------------------
abcd
bcda

I need a query that will allow me to do a like statement to compare the test from the second table to the test from the first table. If it contains that exact string I want it to return the result.

I tried this:

Code:
select a.test arg_1, b.test arg_2, a.result from table1 a, table2 b
where a.test like '%' || b.test || '%'

I know I am being stupid somewhere here. Any help would be appreciated.

Thanks

Cassidy
 

For EXACT srting use equal (=) and not LIKE.
Code:
select a.test arg_1, b.test arg_2, a.result
  from table1 a, table2 b
 where a.test = b.test;
[3eyes]

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Basically I want a contains. So if the string is contained in its entirety inside the field, no matter if anything is before or after it, I want to find it as a match.
 
Try using the instr function:

Code:
select a.test arg_1, b.test arg_2, a.result from table1 a, table2 b
where instr(a.test, b.test) <> 0;
 

Ok, you had it reversed, try this:
Code:
SELECT a.TEST arg_1, b.TEST arg_2, a.RESULT
  FROM table1 a, table2 b
 WHERE b.TEST LIKE '%' || a.TEST || '%';
[noevil]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
...Or maybe not?


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Cassidy,

I don't see anything wrong with your original code. Does it not do what you want?:
Code:
SQL> select * from table1;

TEST      RESULT
----- ----------
abcdB       3316
bcdaB       3345
abcd        3316
wxyz        5555

SQL> select * from table2;

TEST
-----
abcd
bcda

SQL> select a.test arg_1, b.test arg_2, a.result from table1 a, table2 b
  2  where a.test like '%' || b.test || '%';

ARG_1 ARG_2     RESULT
----- ----- ----------
abcdB abcd        3316
abcd  abcd        3316
bcdaB bcda        3345
Let us know how your results differ from mine.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
“Beware of those that seek to protect you from harm or risk. The cost will be your freedoms and your liberty.”
 
Was on the road. You know I thought it would to. However combing over the results and doing the query manually I get more some results manually that I am not getting using the query. I checked for white space and things like that but still not pulling them all. That is why I was bugged and posted. Instr returned exactly the same.

Thanks

Cassidy
 
Cassidy said:
...doing the query manually I get more some results manually that I am not getting using the query.
What is your assessment of how these two scenarios differ? Can you post complete examples of the two scenarios, including the actual code, the data values, and the differing results? (Sumthin's gotta be differnt. <grin>)

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
“Beware of those that seek to protect you from harm or risk. The cost will be your freedoms and your liberty.”
 
That is my thought. I will try to get something to do a comparison on.

Thanks

Cassidy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top