查找 in 查詢的方法
您描述的情況是需要檢查某個用戶是否參與了包含在他存儲在 user_id 字段中的 id 列表內的項目。對于這種情況,mysql 提供了以下方法:
1. 使用 find_in_set 函數:
select * from project where find_in_set($this->auth->id, user_id)
這個查詢將返回 user_id 字段中包含 $this->auth->id 值的 project 行。
2. 使用 like 操作符:
SELECT * FROM project WHERE user_id LIKE '%$this->auth->id'
此查詢將返回 user_id 字段包含以 $this->auth->id 開頭或結尾的字符串的項目行。
? 版權聲明
文章版權歸作者所有,未經允許請勿轉載。
THE END