简体   繁体   English

如何通过替换其他表中两个字段的值来从表中选择所有记录?

[英]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.

相关问题 根据另外两个表从一个表中选择值(关系) - Select values from one table based on two other tables (relational) 如何从一个表中选择所有在mysql中两个其他表的联合中不存在的记录 - How to select all records from a table that do not exist in a union of two another tables in mysql 如果表中不是 null,如何从其他表中获取 select 字段? - How to select fields from other tables if they're not null in table? MySQL 从其他表中选择两条记录? - MySQL SELECT two records from other table? 比较两个表中的所有字段,并从 mysql 中的第一个表中获取不匹配的记录 - Compare all fields from two tables and get unmatched records from the first table in mysql 即使不是一个表中的所有行在另一个表中都有corespondent,如何从MySQL的两个表中进行选择? - How to select from two tables in MySQL even if not all rows in one table have corespondents in the other? 如果第二个表中至少有4条记录,则从两个表中选择记录 - Select records from two tables if atleast 4 records in second table 连接两个表,从两个表中选择值,第二个表没有记录 - joining two tables, select values from two with second table having no records 如何使用 MySQL 中其他两个表的值总和更新表 - How to update a table with sum of values from two other tables in MySQL 从第三张表中选择记录,同时与其他表进行比较 - Select records from third table while comparing between to other tables
相关标签
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM