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

FIND_IN_SET not retrieving results (PHP)

I am troubles with this method not returning results. There are ids within 'table' that match the array. I guess it's not liking something, except I cannot quite put my finger on it. $define = ",8,9,10,"; // ** Data Retrieve ** //…
Brandrally
  • 803
  • 3
  • 14
  • 24
1
vote
1 answer

MYSQL - GROUP_CONCAT AND FIND_IN_SET are mixing values/order?

I have the following problem: I try to select all the votes a user made and put them out in one column. I use GROUP_CONCAT for this, but somehow it is mixing the values order. This is the SQL code: SELECT GROUP_CONCAT(DISTINCT…
Buffer Overflow
  • 946
  • 1
  • 8
  • 9
1
vote
1 answer

MySQL Select row where text field contains number bigger than X

I have a text column ( MISCDATA ) in a database wich contains multiple numeric values and string values, separated by comas and semicolons. Is there a way to build a query to select only the rows where MISCDATA contains a number bigger than 50…
user3529213
  • 73
  • 1
  • 8
1
vote
1 answer

use FIND_IN_SET my sql function with hashed values

I have the following query: SELECT url, url_hash from pages WHERE url_hash IN (SHA1('URL1'), SHA1('URL2'), SHA1('URL3')) ORDER BY FIND_IN_SET(url_hash, "SHA1('URL1'), SHA1('URL2'), SHA1('URL3')") I would to keep the order of the result set the…
Oleg Belousov
  • 9,981
  • 14
  • 72
  • 127
1
vote
1 answer

MySQL find_in_set selecting not working

I'm trying to do the following: Select from current year: Working Select where user_id is in comma seperated list 'users': Works Select where user_id is NOT in comma seperated list 'accepted' OR 'rejected': Not working But for some reason I…
ronnyrr
  • 1,481
  • 3
  • 26
  • 45
1
vote
4 answers

MySql find a value in a comma separated set

I have values stored like this in a field 1,255,230,265. Is there a function in MySQL that will give me the second value in that string? In this case it'll be 255. I tried using locate, but that does not seem to be meant for this.
Norman
  • 6,159
  • 23
  • 88
  • 141
1
vote
1 answer

How I get comma-separated values form table in symfony2?

I have a MySQL table which contains comma-separated values like this: first row=(A,AB) second row=(AC, AE) I want to select the rows which have A in their set not AC OR AE. I am using symfony2 in my code. $query =…
Addy
  • 998
  • 4
  • 12
  • 36
1
vote
3 answers

IN Clause dont work in MySQL for me

I am passing my parameter as 'Suburbun','Indigo' to retrieve records matching both Campaigns in below Stored Procedure created in MySql. CREATE PROCEDURE `DemoSP`(Campaign VARCHAR(3000)) BEGIN SET @query = CONCAT('Select * from vicidial_log…
Akash
  • 19
  • 6
1
vote
1 answer

MySQL FIND_IN_SET(array1, array2)

Is it possible to search for an array of numbers in a comma separated column? I know that this is possible SELECT * FROM products WHERE FIND_IN_SET('1', '1,3,5') > 0 But is this possible too? SELECT * FROM products WHERE FIND_IN_SET('1,2', '1,3,5')…
Mohammad Masoudian
  • 3,483
  • 7
  • 27
  • 45
1
vote
1 answer

query results from comma seperated values and query for each value to display

I have a table with ID, date, and a comma separated field. e.g. values like: id date options 1 2013-12-26 3006,3009,4010 2 2013-12-25 3002,3001,5090 3 2013-12-24 2909,1012,6089 4 2013-12-23 3001,4009,5008 After…
1
vote
5 answers

Left Join with Find in set

I have tables as follows : TABLE A +-----+---------------+-------------+ | ID | DNR_DETAIL_ID | DESCRIPTION | +-----+---------------+-------------+ | 1 | 1 | DESC A | +-----+---------------+-------------+ | 2 | 2 | …
Oğuz Çelikdemir
  • 4,990
  • 4
  • 30
  • 56
1
vote
2 answers

how to use join that pull comma seperated values from MySQL

i have tables tbl_restaurant(name,cuisine_id,....) and tbl_cuisine(cuisine_id,cuisine_name) In tbl_restaurant, cuisine_id field contain comma(,) separated values like (3,6,9,20,31) and when i try to pull cuisine_name using join it only takes first…
Tnd.exe
  • 63
  • 5
1
vote
3 answers

Is there any difference (index selection? speed?) in find_in_set vs or

Is there any difference (index selection? speed?) between: select * from table where x = 'a' or x = 'b' vs select * from table where find_in_set(x, 'a,b') Should I use one of those or are they equal?
Markus
  • 5,667
  • 4
  • 48
  • 64
0
votes
0 answers

select rows where column contains value from comma separated list

I searched for questions like this.. But I could not find answer to fetch data from mysql table. I have mysql table like below : | id | division | branch | 1 | Mumbai | Thane | 2 | Mumbai | Kalyan | 3 | Pune |…
0
votes
0 answers

Multiple WHERE find_in_set lookups

I'm wanting to pull steamid from multiple clubs. Website is based on an Invision Community site. The output is a list of steamids which is imported into our game servers. My simple pull from one club code below works perfectly:
BigD
  • 1