列出多个表中的特定信息

时间:2016-03-03 00:45:20

标签: sql-server select

我有三张桌子:电脑,电脑和员工。我试图找到名为Tracy的员工使用的计算机模型的名称。我将列出每个表的示例。涉及的行和未涉及的行。

电脑桌

 comp |   MFR   |  PROCT
+-----+---------+-------+
|C101 | COMPAQ  | 486DX |
+-----+---------+-------+
|D111 |  Dell   |  simm |
+-----+---------+-------+

电脑桌

 tagnum | comp | local | empnum
+-------+------+--------+-------+
|77740  | C101 | Acct   |  625  |
+-------+------+--------+-------+
|37692  | H125 |  Home  |  456  |
+-------+------+--------+-------+

员工表

 empnum  |   empname   |  empphone |
+--------+-------------+-----------+
| 625    | Tracy S     |   1311    |
+--------+-------------+-----------+
| 119    |  Robert O   |   1312    |
+--------+-------------+-----------+

我的理由是它应该是这样的:

select * 
from computer 
INNER JOIN pc ON computer.COMP=pc.comp 
INNER JOIN employee ON pc.empnum=employee.empnum
where employee.empname='Tracy%'`

但它没有用,我无法弄清楚我误解了什么。

1 个答案:

答案 0 :(得分:2)

select * 
from computer 
INNER JOIN pc ON computer.COMP=pc.comp 
INNER JOIN employee ON pc.empnum=employee.empnum
where employee.empname like 'Tracy%'`

%运算符应该使用like而不是=运算符。