doushizhou4477 2017-06-05 07:34
浏览 24
已采纳

将表连接成4列并显示其他字段

I have a new problem, as information from my question before, i already success show 4 coloumn from joining another table, but i got another problem to show another coloumn/field, for more detail :

Table personal (tbl_personal)

+---+-----+------------+
|ID |Name |Skill       |
+---+-----+------------+
| 1 | Nia | Accountant |
| 2 | Tia | Banking    |
| 3 | Ria | Technicall |
| 4 | Dia | Admin      |
+---+-----+------------+

Table master (tbl_master)

+---+---------+---------+-----------+--------+----+
|ID |Employee1|Employee2|Departement|Division|Note|
+---+---------+---------+-----------+--------+----+
| 1 | 1       | 2       | MSO       | MWS    | etc|
| 2 | 2       | 1       | DSO       | SE     | etc|
| 3 | 3       | 4       | OSO       | GA     | etc|
+---+---------+---------+-----------+--------+----+

I want to show into web page from tbl_master above in codeigniter like this :

+---+-------+-----------+-------+-----------+-----------+--------+----+
|ID |Name 1 |Skill 1    |Name 2 |Skill 2    |Departement|Division|Note|
+---+-------+-----------+-------+-----------+-----------+--------+----+
| 1 | Nia   | Accountant| Tia   | Banking   | MSO       | MWS    | etc|
| 2 | Tia   | Banking   | Nia   | Accountant| DSO       | SE     | etc|
| 3 | Ria   | Technicall| Dia   | Admin     | OSO       | GA     | etc|
+---+---------+---------+-------+-----------+-----------+--------+----+

I already got solution to show Name 1, Skill 1 until Skill 2 with this code :

select tp1.name name1,tp1.skill skill1,tp2.name name2,tp2.skill skill2 
from tbl_master tm
join tbl_personal tp1
on tm.Employee1 =tp1.ID
join tbl_personal tp2
on tm.Employee2 =tp2.ID

but i have another problem to show departemen, Division, and Note fields, if there any advice, please, thanks...

  • 写回答

1条回答 默认 最新

  • dongzhuxun5136 2017-06-05 07:59
    关注

    You just need to change your select and add those columns:

    select tp1.name name1,tp1.skill skill1,tp2.name name2,tp2.skill skill2,tm.Departement, tm.Division, tm.Note
    from tbl_master tm
    join tbl_personal tp1
    on tm.Employee1 =tp1.ID
    join tbl_personal tp2
    on tm.Employee2 =tp2.ID
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程