1.in查詢相當于多個or條件的疊加往果,例如:
select * from user where user_id in (1,2,3);
等效于
select * from user where user_id = 1 or user_id = 2 or user_id = 3;
not in與in相反疆液,如下
select * from user where user_id not in (1,2,3);
等效于
select * from user where user_id != 1 and user_id != 2 and user_id != 3;
1.find_in_set基本語法
FIND_IN_SET(str,strlist)
str 要查詢的字符串,strlist 字段名 參數(shù)以”,”分隔 如 (1,2,6,8)
如果str不在strlist 或strlist 為空字符串陕贮,則返回值為 0 堕油。如任意一個參數(shù)為NULL,則返回值為 NULL肮之。這個函數(shù)在第一個參數(shù)包含一個逗號(‘,’)時將無法正常運行掉缺。
+----+---------+-----------+-------------+
| id | user_id | follow_id | follow_time |
+----+---------+-----------+-------------+
| 13 | 15 ? ? ?| 16,15 ? ? | ?1478096138 |
| 14 | 15 ? ? ?| 17 ? ? ? ?| ?1478177725 |
| 15 | 15 ? ? ?| 19 ? ? ? ?| ?1478181035 |
+----+---------+-----------+-------------+
比如這張表,SELECT * from test where FIND_IN_SET('5',follow_id);這樣是查不到的戈擒,返回值為null,因為follow_id中沒有”5”這個值眶明,它不同于 like 模糊查詢,它是以“,”來分隔值
like是廣泛的模糊匹配筐高,字符串中沒有分隔符搜囱,F(xiàn)ind_IN_SET 是精確匹配,字段值以英文”,
”分