查找 in 查詢的方法
您描述的情況是需要檢查某個(gè)用戶是否參與了包含在他存儲(chǔ)在 user_id 字段中的 id 列表內(nèi)的項(xiàng)目。對(duì)于這種情況,mysql 提供了以下方法:
1. 使用 find_in_set 函數(shù):
select * from project where find_in_set($this->auth->id, user_id)
登錄后復(fù)制
這個(gè)查詢將返回 user_id 字段中包含 $this->auth->id 值的 project 行。
2. 使用 like 操作符:
SELECT * FROM project WHERE user_id LIKE '%$this->auth->id'
登錄后復(fù)制
此查詢將返回 user_id 字段包含以 $this->auth->id 開頭或結(jié)尾的字符串的項(xiàng)目行。