Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone.
I have written a query to search for the pattern below:
a: foobar b: foo

So what I want is:
SQL
IF a Contains b OR b Contains a Then Return true.


The Query I wrote is as below:
SQL
SELECT c1 FROM table WHERE 
INSTR(CAST(c2 as UNSIGNED),CAST(c3 as UNSIGNED))
OR
INSTR(CAST(c3 as UNSIGNED),CAST(c2 as UNSIGNED));


Is there any better way to achieve this kind of two way search so that INSTR needs not to be mentioned twice?
Posted

1 solution

try Switch case..
SQL
select 
Case 
When (a=b or b=a) then 1 else 0 
End
from Table_Name

N:B-I'm not familiar with MySql :)
ref.
http://stackoverflow.com/questions/5282637/mysql-switch-case[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900