この2つのテーブルの別のテーブルに存在しない方法は?別のテーブルに存在しない方法
User_relationships table
、これが私の現在のクエリ
"SELECT * FROM `users`
WHERE CONCAT(first_name, " ", last_name) LIKE '%' . $name . '%'
AND (`role_id` = 6 OR `role_id` = 4)
ORDER BY `first_name` asc limit 15"
であると私はguardian_id(user_id)
がuser_relationships
TA上に存在していないクエリに追加したいですUPDATE 1
select * from `users`
where not exists
(select 1 from `user_relationships`
inner join `users` on `user_relationships`.`guardian_id` = `users`.`id`
where `user_relationships`.`student_id` = 422)
BLE私はこれを試してみましたが、まだ私にゼロ結果を返します。
私は唯一のVAR name = ?
とstudent_id = ?
期待どおりの出力を追加しますか? – 1000111
これを試してみてください**ユーザからu INNER JOIN User_relationships ur ON ur.guardian_id!= u.id WHERE CONCAT(u.first_name、 ""、u.last_name)LIKE '%' $ name。 u.first_nameによる '%' AND(u.role_id = 6 u.orrole_id = 4)の順序ASC LIMIT 15 ** **ここでは**結合**を使用しており、**ユーザーのテーブルのユーザーIDとUser_relationshipsテーブルは同じであってはいけません** ..それが動作するか何か問題があれば教えてください。 –
私の質問を更新します –