My Query which I am sure can be optimized extensively but couldn't say how off the top of my head.
What I have is a post/comment like concept going on for my members. Where they can choose to share it with specific people or everyone. So from this I know my query can potentially cause duplicate results (if I could get it to work in the first place). I need to get a distinct 'ciID' while finding the users ID, along with any potential ID's mentioned else where. The ID's for the members are stored in 3 different columns for 3 different reasons.
mID is the member themselves, then sharedWith and whos_with kinda speak for themselves. I store the id's in sharedWith and whos_with like 1111:2222:3333
But in all I have to search across all 3 columns for the member ID shared, and whos column to make sure I get all the results for the ID's being passed through a function in an array. Which after building the query through a loop I come up with a query like
select DISTINCT(ciID),* from user_posting
where (mID = 21 OR sharedWith LIKE '%21%' OR whosWith LIKE '%21%')
or (mID = 22 OR sharedWith LIKE '%22%' OR whosWith LIKE '%22%')
or (mID = 45 OR sharedWith LIKE '%45%' OR whosWith LIKE '%45%')
limit 1
somewhere in that I have a syntax erro I am not noticing, and I need a pair of eyes to help me out