Rumah > pangkalan data > tutorial mysql > MySQL – finding values in comma seperated string_MySQL

MySQL – finding values in comma seperated string_MySQL

WBOY
Lepaskan: 2016-06-01 13:12:32
asal
908 orang telah melayarinya

MySQL is very strong, popular database stytem using for mainly inPHP MySQL web developmentsolution. In web application development sometime developer store data in comma(,) or pipe (|) etc formats. Finding value(s) from comma seperate MySQl has REGEXP (Regular Express) function. Use this function developer can search or filer one or multiple string value in your field data. Given below example to understand in detail how to use finding value(s) from comma seperate in MySQL Database field.

MySQL database table structure :

employee_hobbyid hobbies--- --------1Travelling2 Suring the Internet3 Reading4 Swimming5 Meeting Friends6 Cooking. .. .10 Watching Movieemployeeidhobby_ids--- ---------1 1,4,3,6,1021,3,4,1037. .. .10 3,5,6,9
Salin selepas log masuk

1. Finding single id in Comma seperate string value (Get all employee id who has hobby “Swimming”) :

SELECT id FROM employee WHERE hobby_ids REGEXP "[[:<:>:]]"</:>
Salin selepas log masuk
Salin selepas log masuk

2: Find multiple id in comma separated string (Get all employee ids who has Travelling,Swimming,Watching Movie hobby) :

SELECT id FROM employee WHERE hobby_ids REGEXP "[[:<:>:]]"</:>
Salin selepas log masuk
Salin selepas log masuk
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan