我有1個查詢可以從內聯合的幫助下從三個表中獲取記錄。重複顯示記錄
table name
tbl_emp as emp
tbl_sal as sal
tbl_address as addr
fields from 3 tables
Schema:
tbl_emp - empid,name,comp_id
tbl_sal - empid - emp_type
tbl_address - emp_type
查詢
SELECT emp.empid, emp.name, sal.salary, addr.address
from tbl_emp as emp
INNER JOIN tbl_sal as sal
ON emp.empid = sal.empid
INNER JOIN tbl_address as addr
ON addr.emp_type = sal.emp_type
where comp_id = '114';
結果表明:
1 abc 1000 test
1 abc 1000 test
1 abc 1000 test
1 abc 1000 test
1 abc 1000 test
2 xyz 2500 main
2 xyz 2500 main
2 xyz 2500 main
2 xyz 2500 main
2 xyz 2500 main
我想導致這樣的:
1 abc 1000 test
2 xyz 2500 main
請幫我在這。
後滿的DDL表,它顯得有些領域被排斥在外。另外一些示例數據會有所幫助。 – 2013-03-04 09:57:09