Reputation: 155
MY DB entry for the field data in the table productinfo is this for example:
66523,665893,745896321
Now I want a SELECT
statement which gives me the hole entry:
For example:
SELECT * from productinfo WHERE products="66523"
Upvotes: 1
Views: 65
Reputation: 1204
Have you tried like this?
SELECT * from productinfo WHERE products like "66523,%" OR products like "%,66523,%" OR products like "%,66523" or products="66523";
Upvotes: 0
Reputation: 7123
select * from productinfo where FIND_IN_SET ('66523', products);
Upvotes: 3
Reputation: 4268
Use this:-
SELECT * from productinfo WHERE products like "66523,%" OR products like ",66523,%" OR products like "%,66523"
It will match anything containing 66523, + something.
OR , + 66523, + something.
OR something + 66523
(last number). It will make sure that whole number is matched.
Upvotes: 0
Reputation: 16351
Try:
SELECT *
FROM productinfo
WHERE Concat(',', products, ',') LIKE '%,66523,%'
In this fiddle, you can check that the first three rows are returned because they contain the 66523 product, but not the 4th one, which contain a product number containing 66523.
But it's a really bad habit to store more than one piece of data into one single field. You should preferably split this data into a new table, using foreign keys. Otherwise, you will be stuck with similar workarounds, without any efficient way to use indexes, and therefore low performances.
Upvotes: 2