Sunday, 18 April 2021

MYSQL FIND_IN_SET() VS FILED() && Laravel eloquent using FIND_IN_SET in where statement

 https://database.guide/the-difference-between-field-and-find_in_set-in-mysql/#:~:text=The%20main%20difference%20between%20these,within%20a%20list%20of%20arguments.

  • FIND_IN_SET() returns the index position of a string within a string list.
  • SELECT FIND_IN_SET('horse', 'Cat,Dog,Horse') AS 'Result';
  • FIELD() returns the index position of a string within a list of arguments.
  • SELECT FIELD('horse', 'Cat','Dog','Horse') AS 'Result';


Use FIND_IN_SET IN laravel
https://stackoverflow.com/questions/35594450/find-in-set-in-laravel-example

$colname = 'css'
$query = DB::table('tags_value')
         ->whereRaw('FIND_IN_SET(?,Tags)', [$colname])
         ->get();

No comments:

Post a Comment