1.in查詢相當(dāng)于多個(gè)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基本語(yǔ)法 FIND_IN_SET(str,strlist) str 要查詢的字符串,strlist 字段名 參數(shù)以”,”分隔 如 (1,2,6,8)
如果str不在strlist 或strlist 為空字符串,則返回值為 0 。如任意一個(gè)參數(shù)為NULL,則返回值為 NULL。這個(gè)函數(shù)在第一個(gè)參數(shù)包含一個(gè)逗號(hào)(‘,’)時(shí)將無(wú)法正常運(yùn)行。
+----+---------+-----------+-------------+
| 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,因?yàn)閒ollow_id中沒(méi)有”5”這個(gè)值,它不同于 like 模糊查詢,它是以“,”來(lái)分隔值 like是廣泛的模糊匹配,字符串中沒(méi)有分隔符,F(xiàn)ind_IN_SET 是精確匹配,字段值以英文”,
”分
|