[英]How to select all records from a table by replacing values for two fields from other tables?
This is the table design of an application I need to build. 这是我需要构建的应用程序的表设计。 Kindly ignore the Role Table in the image.
请忽略图像中的角色表。
Is there any method by which I can select all the records in the table transfer log , but instead of showing "User No" and "Plant No" in the result , I need to show the corresponding Employee No/Username from the user table and corresponding Plant Id from Plant Table. 有什么方法可以选择表传输日志中的所有记录,但是除了在结果中显示“用户编号”和“工厂编号”之外,我还需要从用户表中显示相应的员工编号/用户名,植物表中相应的植物ID。
Try this;) 尝试这个;)
select distinct
log.LogNo, u.EmployeeNo/Username, p.PlantId, log.StartDate, log.EndDate, log.Active
from TransferLog log
left join UserTable u on u.UserNo = log.UserNo
left join PlantTable p on p.PlantNo = log.PlantNo
Use inner join 使用内部联接
select a.*, b.username, c.pantname
from transfer_log as a
inner join User as b a.userno = b.userno
inner join plant as c a.plantno = c.plantno
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.