I have a conversas
table:
STRUCTURE
+--------+---------+
| Nome | Tipo |
+--------+---------+
| id | int |
| users | text |
| titulo | varchar |
+--------+---------+
I need to select the items that contain the user id logged in the users
field.
Example:
table conversations:
+----+---------+------------+
| id | users | titulo |
+----+---------+------------+
| 1 | 2;4;3;6 | Conversa 1 |
| 2 | 3;6;12 | Conversa 2 |
| 3 | 1;5;3;7 | Conversa 3 |
| 4 | 8;2; | Conversa 4 |
| 5 | 1;12;3 | Conversa 5 |
+----+---------+------------+
User Id: 12
Should return:
+----+--------+------------+
| id | users | titulo |
+----+--------+------------+
| 2 | 3;6;12 | Conversa 2 |
| 5 | 1;12;3 | Conversa 5 |
+----+--------+------------+
I tried to use:
SELECT * FROM 'conversas' WHERE users IN (12)
and did not work very well. How should I do it?
-EDIT
I also have a users
and mensagens
table.
users
+--------+---------+
| Nome | Tipo |
+--------+---------+
| id | int |
| nome | varchar |
+--------+---------+
mensagens
+-------------+----------+
| Nome | Tipo |
+-------------+----------+
| id | int |
| id_user | int |
| id_conversa | int |
| mensagem | text |
+-------------+----------+