我有两张桌子
员工
id employee_name JobTitle
---------------------------
1 John CEO
2 Ely MANAGER
3 Marcus MANAGER
4 Steve CEO
5 Fritz ASSISTANT
6 Orly ANALYST
7 Carlo ANALYST
7 Lee MANAGER
JobTitle过滤器
filter_id JobTitle_keyword
---------------------------
1 CEO
2 MANAGER
使用JobTitle_keyword作为过滤关键字是否可行? 所以,如果我运行查询......结果就是这样。
id employee_name JobTitle
---------------------------
1 John CEO
2 Ely MANAGER
3 Marcus MANAGER
4 Steve CEO
7 Lee MANAGER
答案 0 :(得分:2)
您需要加入表格: -
SELECT emp.*
FROM Employees emp
INNER JOIN JobTitleFilter Job
ON emp.JobTitle = Job.JobTitle_Keyword
OR
Select emp.id,emp.employee_name,emp.JobTitle
FROM Employees as emp,JobTitle as Job
Where emp.JobTitle= Job.JobTitle_Keyword
答案 1 :(得分:2)
是的,您可以使用join在MySQL中执行此操作。
SELECT t1.*
FROM Employees t1
JOIN JobTitleFilter t2
ON t1.jobtitle = t2.jobtitle_keyword
检查它是否在this SQL fiddle。
答案 2 :(得分:0)
尝试这个..
SELECT id,employee_name,JobTitle
FROM Employees e
INNER JOIN JobTitleFilter j ON e.JobTitle = j.JobTitle_Keyword
或者您也可以试试这个......
SELECT id,employee_name,JobTitle
FROM Employees e
where e.JobTitle in (Select JobTitle_Keyword from JobTitleFilter)