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
1
vote
1 answer

How can I use FIND_IN_SET within a JOINED table?

I have 2 tables: user: names of registered blood donors with their blood type. blood: contains blood types and blood compatibilities. e.g.: Blood id 5 (A-) can receive blood donations from 5 (A-) and 6 (O-). I have to build a search form that…
Andres SK
  • 10,779
  • 25
  • 90
  • 152
1
vote
2 answers

What's wrong with my sql when I using FIND_IN_SET function?

In my table called testtb has a column that storing file path,Now I want to find the filed which start in C:\.I use the sql,but it always return 0.what's wrong? --example select FIND_IN_SET('C:\\', 'C:\\abc.png' ) -- my sql select …
flower
  • 2,212
  • 3
  • 29
  • 44
1
vote
1 answer

FMDB Database Query IOS FIND_IN_SET()

I am using FMDB database in IOS. In my database I have a one column called tags. Tags column have a comma separated Value like apple,banana,. I want Title column where my keyword matches. I want to know how to search comma separated value in table…
viratpuar
  • 524
  • 1
  • 5
  • 22
1
vote
1 answer

FIND IN SET not working with PDO

I'm having issues with working with mysql's FIND_IN_SET and pdo. This is my code: $statement = $conn->prepare("SELECT * FROM `artistInfo` WHERE FIND_IN_SET(':array', artistServices)"); $statement->execute(array(':array' => '2')); while($row =…
user939951
  • 77
  • 5
1
vote
1 answer

Rails4 FIND_IN_SET with PG not working

Query select * from inboxes where find_in_set ('6',inboxes.to); Above query i am using for accessing record from my table 'inboxes' having one of the column 'to' values like (2,4,6,7) string separated by commas. I am using find_in_set function…
Robin Garg
  • 203
  • 2
  • 13
1
vote
1 answer

php | Convert array to FIND_IN_SET

I'm trying to convert my array to query string. May be you can help me. My array looks like: Array ( [3] => Array ( [0] => 7 [1] => 13 [2] => 1 ) [4] => Array ( [0] =>…
XTRUST.ORG
  • 3,280
  • 4
  • 34
  • 60
1
vote
0 answers

Indexing for find_in_set usage

I am using inner join on 3 tables and one of my columns in one table is comma separated values(varchar) like m03412,3456,skeys and I am using FIND_IN_SET in one of the inner joins. Query takes around 3 mins . Is there any way to reduce the time by…
Learner2011
  • 287
  • 2
  • 6
  • 25
1
vote
2 answers

Select query with comma and join

I have tbl A and tbl B as below and I would like to get their names which is seperated by comma but I am not getting in the format I am looking for. http://sqlfiddle.com/#!2/149093/10 User: 1,2,3 ;2 - I should also get names A,B,C and then B But I…
jason
  • 3,932
  • 11
  • 52
  • 123
1
vote
2 answers

MySQL: creating comma separated list and using in IN

My function code is like following. DECLARE ids VARCHAR(55); SELECT GROUP_CONCAT(id) INTO ids FROM tableName WHERE ...; SELECT CONCAT(GROUP_CONCAT(id), ids ) INTO ids FROM tableName .....; SELECT column_name FROM tableName WHERE id IN…
Ammar Hayder Khan
  • 1,287
  • 4
  • 22
  • 49
1
vote
2 answers

Delete some part of a row from database ( a value in a set of the daatabase row )

I want to delete a part of my row in mysql. like this: my row: 1,2,3,4 I want to make it: 1,2,3 how can I do that? I know it can be done with this code but is there a better way? UPDATE Table SET message = REPLACE(message, ",4", "") WHERE id = 1;
Majid Sadr
  • 911
  • 7
  • 18
1
vote
2 answers

i want to fetch comma separated record in mysql database

In my database table I have 6 Columns id(auto),title,news,image,type I write this query. select id,title,image from add_news where FIND_IN_SET('Travel','Music',type) ORDER BY id DESC I am getting this error Incorrect parameter count in the call…
Hirdesh
  • 163
  • 4
  • 16
1
vote
2 answers

FIND_IN_SET for part of string in Mysql

I need to make a query to a table in my database. Until now I was using FIND_IN_SET because I have strings like this: "twitter,bycicle,car". Then, I could search by FIND_IN_SET("twitter", nameOfColumn) But now, I need to search just part of each…
Biribu
  • 3,615
  • 13
  • 43
  • 79
1
vote
2 answers

SubQuery using IN operator

I have a table named 'user_permission' there is a column named location_ids and data type is varchar(255). I stored here value like 10,27,36. Now I want to use this 'location_ids' in a IN comparison operator. The following query I have tried, but I…
mizan3008
  • 369
  • 3
  • 17
1
vote
1 answer

displaying related records vb.net mysql

i have some strange searching criteria. first let me clarify it, i have a table like this acct_no | name | connected_acct ---------------------------------- 1 | name_1 | 5,6,7 2 | name_1 | 11,12,13 …
Advitiya
  • 13
  • 3
1
vote
1 answer

MySQL SELECT DISTINCT field from second table using a relationship

Let's say we have a tally_sheets table which contains some tally sheets information like in the following description and a persons table described below with a tally_sheets field containing a list of tally sheet's IDs separated by comma. Every…
SYNCRo
  • 450
  • 5
  • 21