'Flexible search Query for stringset?
Please find the below query:
Table Name : B
query : select * from {B}
ID comp
1 d,e,f
I want to check if the value 'f' is present in comp, or not, using an SQL/Flexible search Query.
Is it possible to write a sql query for this scenario?
Update :
SELECT DISTINCT {b:pk} FROM {A AS a left join B as B on {a:ncode} = {b:ncode} and {a:qCode} = {b:qCode}}
WHERE
{a:compID} IN ()
Assume a:compID is "f"
What should be my subquery after the IN operator to achieve my requirement?
Solution 1:[1]
SELECT * FROM {B} where {comp} LIKE '%,f,%'
Solution 2:[2]
You can search in string in mysql:
//full search:
SELECT * FROM A WHERE comp LIKE '%f%'
// start with f
SELECT * FROM A WHERE comp LIKE '%f'
// end with f
SELECT * FROM A WHERE comp LIKE 'f%'
Solution 3:[3]
This will work:
SELECT FIND_IN_SET('f',(SELECT comp FROM t));
If you want to check present or not present then:
SELECT case when FIND_IN_SET('f',(SELECT comp FROM t))=0 then'not present'
else 'present' end from dual;
Solution 4:[4]
Start with f
LIKE 'f%'
End with f
LIKE '%f'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | SherylHohman |
| Solution 2 | SherylHohman |
| Solution 3 | SherylHohman |
| Solution 4 | adrmnt |
