I have a MySQL table with a VARCHAR column VISITOR_ID
that saves multiple or single visitor id values. I want the ENTERED_TEXT to have a 1 to many relationship, and don't want to make multiple rows for that relationship to the VISITOR_ID - So I elected to add multiple id's to the VISITOR_ID column. I now want to search that column for multiple related id's.
| VISITOR_ID | ENTERED_TEXT |
------------------------------------------
| 123,133,777 | text text |
| 555 | text text text |
| 444,133,777 | text |
| 999 | text text text text text |
When I try to use a select with IN()
SELECT *
FROM `My_Table`
WHERE
VISITOR_ID IN(444,777)
I only get back one row and an error:
| 444,133,777 |
Warning: #1292 Truncated incorrect DOUBLE value '123,133,777'
I expected these two rows returned:
| 444,133,777 |
| 123,133,777 |
Yet:
If I use:
SELECT *
FROM `My_Table`
WHERE
VISITOR_ID IN(555,999)
I get back the 2 rows that have the single values in them:
| 555 |
| 999 |
I think I understand that the comma separated values are not being seen as separate values by my IN() clause, but are being seen like this '123,133,777' instead - but how would I have these values read as separate values appropriate for my IN() search?
I was trying to change the column type, and also various means of splitting the values. Not sure what is the best way to go. I also understand I can remedy this by using individual rows for the VISITOR_ID - which I am considering. It is just that I thought it made sense to have these multiple ID's share a similar single text value entered by a user. It seemed 1 record would be better than many? not sure this is the way to go.