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
0 answers

Sql query using Find in set with multiple values

I need a query to select all rows where it selects all rows based on multiple product ids in products and exclude products with ids as well and include the blank ones as well. See the image for more details I have written a query but the blank…
user399883
  • 243
  • 1
  • 3
  • 11
0
votes
2 answers

Results not showing in MySQL with NULL values

So I have a query set up in MySQL as below but for some reason it will not include results where the column 'contact_CompanyID' is NULL. In theory, the query should not include results where the 'contact_CompanyID' is equal to either 2311 or 1, so…
Darren
  • 73
  • 1
  • 1
  • 11
0
votes
1 answer

MYSQl - Check if group of dates are in a comma separated list of dates

My table design: How to get the records If dates '04-11-2016' OR '11-11-2016' available in week_days column. Note: The dates are not same, It's have one or more dates. Actual Query: SELECT * FROM `sh_products` WHERE…
Ramalingam Perumal
  • 1,367
  • 2
  • 17
  • 46
0
votes
1 answer

MySQL - Using FIND_IN_SET on Multiple Tables with No Relation

My database structure looks something as follows: Database Name: Products id ptype 1 Cups 2 Shirts 3 Cups 4 Mugs 5 Fabric 6 Mat Database Name: Categories id category ptype 1 Clothes Pants, Shirts, Tshirts 2 Other Mugs, Cups I want to…
Saad Bashir
  • 4,341
  • 8
  • 30
  • 60
0
votes
1 answer

MySQL - FIND_IN_SET for comma separated field values

I have few fields in one table which are storing comma separated values. I can show query using like or FIND_IN_SET to find data from comma separated values. MySQL query finding values in a comma separated string However, I would like to know that…
Amit S
  • 44
  • 5
0
votes
1 answer

Filter records using a comma separated string

I've a string variable @IDS and I'm trying to filter the records from table user but nothing helping me out since I'm new to MySql. SET @IDS = '1,2,3'; select * from user where find_in_set(@IDS,ID);
M.S.
  • 4,283
  • 1
  • 19
  • 42
0
votes
1 answer

Select multiple data from other table for each id separated by comma

Table one - workorder ╔══════════╦══════════════╦══════════════╗ ║ id ║ wpeople ║ start_date ║ ╠══════════╬══════════════╬══════════════╣ ║ 1 ║ 1,2,4 ║ 02.08.2016 ║ ║ 2 ║ 4,5 ║ 28.09.2016 …
zmeutz
  • 37
  • 2
  • 10
0
votes
1 answer

Searching comma related value with FIND_IN_SET with multiple search string Codeigniter

I am using FIND_IN_SET to get similar comma related values from database the problem what i am facing is if in string i am passing single value it is searching accurately but if i am sending multiple value in string it is not able to search $search …
Sumit Nair
  • 327
  • 1
  • 4
  • 20
0
votes
3 answers

Find_in_set returns an empty set?

I have some questions about the set type in find_in_set here is the code: create table set_test(id int,set_col SET('a','b','c','d')); insert into set_test(id,set_col) values(1,'a,b'),(2,'a,b,b'); select * from set_test where…
dbTry
  • 13
  • 4
0
votes
2 answers

SQL Server 2014 equivalent to mysql's find_in_set()

I'm working with a database that has a locations table such as: locationID | locationHierarchy 1 | 0 2 | 1 3 | 1,2 4 | 1 5 | 1,4 6 | 1,4,5 which makes a tree like…
MMDeveloper
  • 3
  • 1
  • 3
0
votes
1 answer

MySQL multiple results with find in set of values

I need to get multiple rows with articles where the article IDs are in the list below. (in the string list) SELECT id, title FROM articles WHERE FIND_IN_SET(id, "1,2,3,4,5,9,25"); How to do that correctly?
acoder
  • 667
  • 2
  • 9
  • 19
0
votes
2 answers

MySQL FIND_IN_SET not working

I have these tables Irasai table invoice_nr | pard_suma | pard_vad | pirk_vad 1122 200 2,4,6 2,1,3 1111 502,22 3 4 1112 5545 3 4,1 54151 1000 2 1 74411 …
Rytis
  • 59
  • 8
0
votes
1 answer

How to make no rows display in mysql when the IN is empty

I have used the following query to get the data from database its working fine when the IN () is not empty but how can i restrict it as displaying no rows When my IN is empty SELECT `id`, `date`, `user`, `type`, `module`, `action`, `ip_address`,…
Raja Manickam
  • 1,743
  • 4
  • 20
  • 28
0
votes
1 answer

Mysql JOIN tables with preference and a GROUP BY

I'm working on an file/image database. I have one table that indexes the file names and attaches them to an 'album' FILES TABLE file_id | file_name | album_id 1 | image x | 2 2 | image y | 2 The second table stores the location…
MF_it
  • 23
  • 9
0
votes
1 answer

MySQL Multiple Join with delimiting via FINDINSET

I am attempting to JOIN onto two different columns in the first table below from columns in the second and third tables. I wish to JOIN users.id to job_listings.id to return users.username, and to also JOIN and delimit job_listings.categories to…
ZBM 2
  • 5
  • 1