How to get all rows from a table if a similar statement value matches mysql?

I am trying to get the whole record if the parameter value , like , is true.

I have a table ticket.

---------------------------
: id  :  ticket : user_id :
---------------------------
: 1   : 2546    : 2       :
---------------------------
: 2    : 8475    : 2      :
---------------------------

I am trying to fulfill this request

SELECT * FROM `ticket` WHERE `ticket` LIKE '%2546%'  

The above query returns one result and works fine. But I need both rows if the correspondence of the value is like , and the table has more entries for this row user_id . I tried a group

SELECT * FROM `ticket` WHERE `ticket` LIKE '%2546%' 
GROUP BY `user_id `

I know that this can be done if used user_id = 2instead of likeand Group By, but I need to filter the column ticket. So is it possible to achieve this kind of tasks in one request?

+4
2

:

SELECT *
FROM ticket t1
WHERE user_id IN (
    SELECT DISTINCT user_id
    FROM ticket t2
    WHERE ticket LIKE '%2456%'
);
+6

self join

SELECT U . * 
FROM  `ticket` t, `ticket` U
WHERE t.`ticket` LIKE  '%2546%'
AND t.`user_id` = U.`user_id` 
+2

All Articles