
I want to select id in the database table where allot field have a specific integer value in the string.
example:- In the allot column I want to search value 26 in Comma(,) separated string, here result should be id=72
Fix your data structure! You should be using a junction/association table with one row per value and per id. That is the SQL way to represent the data. Why is your structure bad?
Sometimes, we are stuck with other people's really, really bad design decisions. In those cases, you can use like:
SELECT p.id
FROM Prospects p
WHERE ',' || allot || ',' like '%,26,%';
try the commend 'SELECT id FROM (table_name) WHERE allot LIKE '%,26,%'
the '%x%' will look for anything with an x in it in the provided column
basically if you find something with x give it to me
Using the LIKE operator you should be able to solve your requirement. Considering that your table name is Prospects:
SELECT id FROM Prospects
WHERE allot LIKE '%,26,%'
EDIT-1: You can narrow down the search finer by adding additional commas in the query as mentioned here!
EDIT-2: To additionally handle scenarios, you can have the same query with a UNION like this. This is not something that you should be looking to implement, but implement a stored procedure to check these scenarios and handle it in your logic.
SELECT id FROM Prospects
WHERE allot LIKE '%,26,%'
UNION
SELECT id FROM Prospects
WHERE allot LIKE '%,26%'
UNION
SELECT id FROM Prospects
WHERE allot LIKE '%26,%'
Hope this answers your question!