是否可以选择字段匹配时,或者连接的表字段是否匹配:
用户表:
---------------------------
|user_id |job_title |age |
---------------------------
|1 |hardware |22 |
|2 |software |45 |
---------------------------
体验表:
-------------------------
|id |user_id |job_title |
-------------------------
|1 |1 |random |
|2 |2 |random |
|3 |2 |hardware |
-------------------------
我需要一个查询,当job_title来自任何一个表的'hardware'时,它将返回两个用户...
SELECT
user_id u
FROM
users
JOIN experience e ON e.user_id = u.user_id AND e.job_title LIKE '%hardware%'
WHERE
u.age > 18 AND
u.job_title LIKE '%hardware%'
答案 0 :(得分:0)
这样的东西?根据您的问题,只有一个job_title必须是"硬件"?
SELECT user_id u
FROM users u left join experience e
on e.user_id = u.user_id
WHERE u.age > 18 AND
(u.job_title LIKE '%hardware%' OR e.job_title LIKE '%hardware%')