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

want to Write a Stored Procedure in MYSQL

i have 3 tables e.g A, B, C want to select from A then Update B and Insert into C i hv written SP like This. DELIMITER // CREATE PROCEDURE ABC( IN id int ) BEGIN SELECT * FROM A WHERE FIND_IN_SET(LEFT(A.id,10),id); UPDATE B …
Safi
  • 11
  • 4
0
votes
0 answers

mysql FIND_IN_SET returned an empty result set

I have the following input table "eastate_facilitylist": eastate_id facilityList 1 2,3,4 2 1,3,4 3 1 I want to select the "eastate_id" values that have a value inside it, so I've crafted the following query: SELECT eastate_id FROM…
0
votes
2 answers

In MySQL - 2 LEFT JOINs with FIND_IN_SET show wrong numbers

I have one main table and 2 tables that I left-join using "FIND_IN_SET". When I use a function such as COUNT() or SUM() I get wrong numbers! They are totally fine when I left-join only one table. I simplified the tables for the example: CREATE TABLE…
Guy Arnon
  • 31
  • 5
0
votes
2 answers

How to find Array values to search in FIND_IN_SET

Hi I am facing a problem with Laravel eloquent query. I have a table named as 'Offer' and it is connected to another table using relation function 'ApplyOn'. here is the code $offer = Offer::whereHas('ApplyOn',function($query) use ($input){ …
Akshay
  • 15
  • 4
0
votes
1 answer

Php Mysql find in set query /// i want to convert this query in laravel query builder

select * from settings where setting_type='admin_privilege' and FIND_IN_SET ('001',`setting_value`) and br_id=4
0
votes
0 answers

Show other rows in MySQL table where a rows have a string with comma matched with a id

I have a table called leads, and the other table is users. Now when the lead is consumed by the user, the field 'consumed_user_id' in leads adds the user_ids with comma delimiter in this field like (21,22,23,24). and other field is hide_seller_id,…
0
votes
1 answer

normalizing existing data; varchar list to integers

Normalizing an existing table I made a decade ago. I have a varchar column (platforms) with a list of numbers that I'd like to break down and place into a separate table. [table_A] id int platforms varchar other fields.... An example for…
Phaelax z
  • 1,814
  • 1
  • 7
  • 19
0
votes
0 answers

FIND_IN_SET() in mysql query makes the query very slow?

Here is my query where I am getting list of all children categories for parent category which is 3 SELECT GROUP_CONCAT(lv SEPARATOR ',') FROM ( SELECT @pv:=( SELECT GROUP_CONCAT(id SEPARATOR ',') …
rajwa766
  • 604
  • 13
  • 31
0
votes
0 answers

Pass string (csv) to stored procedure and search column (csv) contains

I started working in an existing system and facing the below issue in my table having a field "tags" related to a site article were stored like this: row1 "dotnet,oracle,training,tutorials,oops" row2 "java,oracle,training,tutorials,oops" row3…
Vinod Kannan
  • 37
  • 1
  • 1
  • 7
0
votes
0 answers

rails/PostgreSQL query which contains the search string

I am using ror framework to generate a rest api with PostgreSQl as a database. I have a table with the following structure: orders id: uuid code: int8 Rows: 1 1000000045 So, the above row should be selected when the user types in either 45 or 4. How…
Ashy Ashcsi
  • 1,529
  • 7
  • 22
  • 54
0
votes
3 answers

FIND_IN_SET equivalent to SQL Server with IF Condition

I need a help with the below statement: if( FIND_IN_SET(m.iCodFormaPgto, p.cValor) > 0, 'Delivery', seg.CNome) as fato_vnd_seg_virtual I tried all sorts of solutions, but I can't reproduce the same scenario in SQL Server. Below, I'll put all the…
0
votes
1 answer

MySQL FIND_IN_SET search result needed in original sequence

I am using FIND_IN_SET in MySQL as below : SELECT color, b.id FROM cards b where FIND_IN_SET(b.color, 'gold,gold,bronze,silver,silver') > 0 GROUP BY b.id ORDER BY RAND() limit 5; And I get output as…
rohan koshti
  • 313
  • 4
  • 17
0
votes
0 answers

MySQL/ PHP - Search on comma separated column

I have tables as following staff ----------------- id name operations 1 Mr X 51,52 2. Ms Y 71,72,74 3 Ms Z 71,72,74,80,81,82 operations --------------- id name 51 BT 52 BP 71 CV 72 DX 74 EG 80 SR 81 FT 82 ZS I would like to…
0
votes
0 answers

Query issue with selecting GROUP_CONCAT where FIND_IN_SET

Can somebody help me clarify what I'm doing wrong here? The query runs fine without the "AND FIND_IN_SET(40, tags) > 0" Query error: Unknown column 'tags' in 'where clause' - Invalid query: SELECT SQL_CALC_FOUND_ROWS `tbltickets`.`ticketid` AS…
Tyler Fontaine
  • 131
  • 2
  • 12
0
votes
0 answers

MariaDB Query works and MYSQL does not

I have two web sites with identical database tables. If the following query is run on the site using 10.2.25-MariaDB-log it works, but if run on the site using MYSQL 5.6.45 it does not. Here is the query: SELECT masterpoints_total, FIND_IN_SET(…
Bill
  • 77
  • 1
  • 10