我遇到了一种情况,我必须从三个不同的表中获取数据,我想使用单个查询,因为.How --我们可以这样做-- .Please帮助我吗?
在这种情况下:
table_one
emp_id dept_id name
GT102 206 Test
GT103 201 Test1
GT105 111 Test2
GT106 340 Test3
table_two
Dept_id department
111 Finance
340 Product
201 IT
table_three
emp_id Salary
GT102 10,000
GT103 20,000
GT105 40,000
GT106 50,000我想要考研的部门和薪水,请帮帮我
发布于 2014-02-21 10:43:38
试试这个:
SELECT t1.name,
t2.department,
t3.salary
FROM table_one t1
INNER JOIN table_two t2
ON t2.dept_id = t1.dept_id
INNER JOIN table_three t3
ON t1.emp_id = t3.emp_id
WHERE t1.name = 'Test2' 发布于 2014-02-21 10:42:16
试试这个:
Select table_two.department, table_three.Salary From table_one, table_two, table_three where table_one.emp_id = table_three.emp_id and table_one.dept_id = table_two.Dept_id and table_one.name='Test2'发布于 2014-02-21 10:47:53
select table_two.department,table_three.Salary from table_one join table_two on table_one.dept_id=table_two.dept_id join table_three on table_three.emp_id= table_one.emp_id WHERE table_one.name like 'Test2';
https://stackoverflow.com/questions/21931923
复制相似问题