从另一个表中获取数据? (MySQL的) [英] Get data from another table? (MySQL)

查看:264
本文介绍了从另一个表中获取数据? (MySQL的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MySQL 2005.



所以这是我的问题。

我有这张桌子:

I am using MySQL 2005.

So this is my problem.
I have this table:

Counter     Name     EmployeeNo
   1        Marc      2014001
   2        Mika      2014002
   3        Holly     2014003
   4        Cara      2014004





和另一张表:



and this other table:

ID     Customer     EmployeeNo     Status
001      1B001        2014001        y
002      1G003        2014001        x
003      1G004        2014002        y
004      1B006        2014003        x





我怎样才能显示一张表格,我将它们加在一起如下:



How can I show a table where i join them together like this:

Name    Customer
Marc     1G003
Mika     NULL
Holly    1B006
Cara     NULL





就像检查他们被分配的客户一样。但只显示状态为'x'的客户???


超级帮助!并且提前非常感谢!



like checking the customers they've been assigned with. But only shows the customer with the status 'x' ??

Super Help! And super thanks in advance!

推荐答案

使用SQL Join子句。左外连接返回t1中的所有行,即使t2中没有相应的行



选择t1.name,t2.customer

t1 left外部联接t2在t1.EmployeeNo = t2.EmployeeNo和t2.status ='x'
Use a SQL Join clause. The Left outer join returns all rows in t1 even if no corresponding row in t2

select t1.name, t2.customer
t1 left outer join t2 on t1.EmployeeNo = t2.EmployeeNo and t2.status = 'x'


这篇关于从另一个表中获取数据? (MySQL的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆