Questions tagged [find-in-set]

MySQL FIND_IN_SET() returns the position of a string if it is present (as a substring) within a list of strings.

MySQL FIND_IN_SET(str, strlist) is a string function that returns the index position of the search string str inside the string list strlist. The string list itself is a string containing substrings separated by ‘,’ (comma) character.

This function returns 0 when search string does not exist in the string list and returns NULL if either of the arguments is NULL.

Syntax

FIND_IN_SET(search_string, string_list)

Arguments

  • search_string: a string which is to be looked for in following list of arguments.
  • string_list: list of strings to be searched if they contain the search string.

Example

The following MySQL statement finds the search string ‘ank’ at 2nd place within the string list. So it returns 2.

Code

SELECT FIND_IN_SET('ank','b,ank,of,monk');

Output

FIND_IN_SET('ank','b,ank,of,monk')
2
149 questions
0
votes
3 answers

Update mysql table based with group_concat

UPDATE BELOW! Who can help me out I have a table: CREATE TABLE `group_c` ( `parent_id` int(11) unsigned NOT NULL AUTO_INCREMENT, `child_id` int(11) DEFAULT NULL, `number` int(11) DEFAULT NULL, PRIMARY KEY (`parent_id`) ) ENGINE=InnoDB; INSERT…
Nin
  • 2,960
  • 21
  • 30
0
votes
4 answers

MySQL: Usage of 'REGEXP' instead of 'FIND_IN_SET'

I am having limitation in using MySQL's FIND_IN_SET function for searching array in set. Hence thinking of using of REGEXP. However can anyone help me constructing it. E.g. My requirement SELECT * FROM table AS t WHERE FIND_IN_SET('1,2,3',…
Abhishek Madhani
  • 1,155
  • 4
  • 16
  • 26
0
votes
1 answer

Select column containing value from 1 row using find_in_set

I have a table with many rows and columns. I want to find the column containing a certain value, but search only 1 row, when ID=7. What is the correct way of writing the following expression? SELECT * FROM mytable WHERE FIND_IN_SET(400,…
0
votes
2 answers

find_in_set AND find_in_set not working

Trying to pull this query off, but it won't take ? SELECT cute_news.title, cute_news.id, cute_news.keywords, cute_fields.post_id, cute_fields.alternate_url FROM cute_news, cute_fields WHERE cute_news.id = cute_fields.post_id AND FIND_IN_SET…
eberswine
  • 1,224
  • 3
  • 20
  • 39
0
votes
2 answers

selecting all rows where a column has an specific ID

So I have a badly designed database (I think) which I can't change. It's a twitter like app where the users can follow each other. Every user has it`s row in the table, and in that table there is a column named 'following' which represents all…
Vladimir Szabo
  • 448
  • 4
  • 18
0
votes
3 answers

How do I Use Wildcard (%) to Search but not include spaces?

I have a list of comma separated tags in a column in my database. I was using a simple wildcard to pull items that matches a tag that I was searching for. However, I have discovered that some tags are included as part of a title for other tags and…
Nicholas Cardot
  • 956
  • 1
  • 11
  • 30
-1
votes
1 answer

Multiple search with FIND_In_SET

My database structure is as follows : id values 1 10,15,50,89,200,590 2 30,50,89,45,20 3 15,20,40,50,10,500 4 20,30,90,89,50 I want to write a query to filter the data as follows : 2 30,50,89,45,20 4 20,30,90,89,50 That…
Hossein
  • 67
  • 1
  • 9
-1
votes
1 answer

Add second column to order by mysql in a group_concat

I have this query I made based on someone else question here. SELECT *, FIND_IN_SET( score, ( SELECT GROUP_CONCAT( score ORDER BY score ASC) FROM EventPlayerResult WHERE eventId = 'EventTest0') ) AS position FROM EventPlayerResult WHERE eventId =…
DrDoom
  • 149
  • 3
  • 16
-1
votes
1 answer

MYSQL - Possibly FIND_IN_SET

I'm really struggling to figure this query out: names zone zones zone_active bob 1 1,2 yes bill 0 3 yes james 1 1,2 yes fred 1 1,2 no barry 1 4 yes Im selecting zones '1,2' and zone_active='yes' But it's returning all rows except…
Max Thorley
  • 173
  • 1
  • 17
-1
votes
1 answer

MySQL query joining issue while using FIND_IN_SET and GROUP_CONCAT

So I have a product/categories/brands structure where a products categories are identified by a column containing a comma separated list of category IDs, i.e. 101,105,108, as well as a brand ID column. I'm trying to get a list of all the products,…
HirtLocker128
  • 167
  • 1
  • 1
  • 11
-1
votes
1 answer

How to compare comma separated field with column in mysql?

What I have with me? A string with comma separated : $str_states = "1,2"; I have a table with the following: id event_name states 1 ABC 1,4,5 2 PQR 1,2,3 3 XYZ 3,4,5 What I want: id event_name states 1 ABC 1 2…
-1
votes
2 answers

mysql query showing error: #1241 - Operand should contain 1 column(s)

Mysql query, SELECT qcat.name, COUNT( CASE WHEN qas.state = "todo" THEN 1 END ) AS gtotal, COUNT( CASE WHEN qas.state = "gradedright" THEN 1 END ) AS rightanswer, COUNT( CASE WHEN qas.state = "gradedwrong" THEN 1 END ) AS wronganswer,…
-1
votes
1 answer

Query with FIND_IN_SET and array

I have two tables tbl_user and tbl_projects tbl_user +-----+------+--------+ | id | name | skills | +-----+------+--------+ | u1 | x | s1,s2 | | u2 | y | s2,s3 | | u3 | z | s3,s1 …
Croos Nilukshan
  • 154
  • 1
  • 14
-2
votes
3 answers

How to get rows which contains unknown values in SET column?

Database is MySQL 5.6 CREATE TABLE set_t ( set_r SET ('a', 'b', 'c') ); INSERT INTO set_t (set_r) VALUES ('a,b,c'), ('a,b'); In my case i know only 'a' and 'b'. For example, need to select row where set_r is "a,b,c". Value 'c' is unknown, cant…
ilya iz
  • 470
  • 1
  • 6
  • 19
1 2 3
9
10