I want to check if the table ssd
has a row containing the value 2280
(a substring) and it does but the problem is I can only get a string to check which contains multiple values including the substring. The table ssd
:
----+-------------------
id | m2len
----+-------------------
1 | 2280
----+-------------------
2 | 2260
----+------------------
The query:
$m2len = "2242 2260 2280 22110"
$sql = "SELECT m2len FROM ssd WHER m2len LIKE '%$m2len%'";
This query gives no output even if the table ssd
has the row m2len
containing the value 2280
.
Is there a way to check whether a row contains a substring (2280
) from a string (2242 2260 2280 22110
) with MySQL?
Note: This question may look similar to SELECT MySQL field that contains a substring but it's not as the other question simply checks if a string contains a substring but here I am trying to do the opposite.
Update:
@JohnWoo's Answer Worked. But there's a problem for other values like 0
, 80
, 22
it returns those rows as well which is not required. I want an exact match.
The table may also contain values like:
id | m2len
----+-------------------
1 | 2280
----+-------------------
2 | 2260
----+------------------
3 | 0
----+------------------
4 | 80
----+------------------