dongxiao_0528 2013-07-26 07:01
浏览 203
已采纳

将两个表中的类似数据合并到一个表中

this is an illustration of what I need to do..

TABLE 1

  `----------
    ID     VALUE

    123    A

    123    B

    123    C

    123    D

    123    E

    123    F

    ----------`

TABLE 2

----------
ID        VALUE    STATUS

123        A       POSTED

123        B       POSTED

123        C       CANCEL

----------

OUTPUT

----------
VALUE     ID

A         POSTED

B         POSTED

C         CANCEL

D

E

F

----------

When I search for the ID, everything that has the ID in TABLE 1 needs to be shown when it has a duplicate in table 2 information that does not exist in TABLE1 should merge to be shown in an OUTPUT TABLE... I can only search using the ID

can anyone give me a headstart on how to achieve this in php., mysql is the database ., Im new to this., thanks in advance.. :)

the tables are from two different databases..

  • 写回答

4条回答 默认 最新

  • douyi7055 2013-07-26 07:14
    关注
    select t1.id, t1.value,t2.status from table1 t1 
    left join table2 t2 on 
    t1.value = t2.value where t1.id = <urID>
    

    fiddle

    If tables are on two database:

    select t1.id, t1.value,t2.status from db1.table1 t1 
    left join db2.table2 t2 on 
    t1.value = t2.value where t1.id = <urID>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制