M
M
Mike Gasper2014-02-27 21:36:01
PHP
Mike Gasper, 2014-02-27 21:36:01

Creating a SQL query with a complex LIKE condition?

There is a cell users with values ​​(1,2,3,4,5,6...). From the user I get a number and I need to select the emails of everyone who has this number in this cell. Help me compose the correct SQL query.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Logachev, 2014-02-27
@gasperoid

Anything like this?

SELECT *
FROM `table`
WHERE `users` REGEXP '([^0-9]{$user}[^0-9])'

dev.mysql.com/doc/refman/5.6/en/regexp.html
Either like this:
SELECT *
FROM `table`
WHERE `users` LIKE '{$user},%' OR `users` LIKE '%,{$user},%' OR `users` LIKE '%,{$user}'

A
Alexander Khirenko, 2014-02-27
@Satanpit

If I understand the problem correctly:

SELECT email FROM `users` WHERE FIND_IN_SET(1,  usergroups)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question