Select only items that contain the number in their value

0

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     |
+-------------+----------+
    
asked by anonymous 04.02.2016 / 15:25

1 answer

-1
SELECT * FROM tabela_conversas WHERE users LIKE '%12%';

Remembering that it would be more ideal to create a separate relationship table for that case.

    
04.02.2016 / 15:52