0

I want to retrieve all data where the delivery_id is equal 5 and that delivery_id is in array.How to do?.This is my problem.

my database is

sale_code    seller_id     product     delivery_id
202108        6           some1         [5,1]
202108        4           some2         [7]
202109        5           some3         [5]
202109        4           some4         [7,1]
thaw zin
  • 3
  • 2
  • 3

2 Answers2

2

You have 4 cases. I have them in or logic

select * from tbl 
where (delivery_id like '[5,%' or delivery_id like '[%,5]' or delivery_id like '%,5,%' or delivery_id like '[5]')
zip
  • 3,938
  • 2
  • 11
  • 19
  • 1
    You missed the instance where 5 is the only value in the list. – Turophile Jan 21 '20 at 04:06
  • Sorry Sir, I give you feedback and response for your answer.But show me alert that is "Thanks for the feedback! Votes cast by those with less than 15 reputation are recorded, but do not change the publicly displayed post score.".I don't understand that.I am newbie in SOF. – thaw zin Jan 21 '20 at 10:10
0
select *
from table1
where delivery_id LIKE '[5,%' 
or delivery_id LIKE '%,5]' 
or delivery_id LIKE '%,5,%' 
or delivery_id = '[5]' 

It goes without saying that this is terrible - you should not be storing your data like that with multiple values in a list within a column.

EDIT: If you are using mySQL you can use the REGEXP function:

select *
from table1
where delivery_id REGEXP '[\[,]5[\],]'
Turophile
  • 3,367
  • 1
  • 13
  • 21