doutuzhuohao6449 2018-02-15 16:59
浏览 195
已采纳

MYSQL LEFT JOIN 3表(第一个表返回空值)

I can't figure out why Table A is returning null value after I left join with Table B. It should be 3 tables but for now, i'm just getting the two tables to work.

Table A
IUEID  DATE  MONTH  DATAA
4444   01    JAN    150
4444   02    JAN    98
4444   03    JAN    78
4444   04    JAN    55 

TABLE B
IUEID  DATE   MONTH  DATAB
4444   02     JAN    CORN
4444   03     JAN    GRAPES

SELECT *, TABLEB.DATAB
FROM TABLEA
LEFT JOIN TABLEB
ON TABLEB.IUEID = TABLEA.IUEID
AND TABLEB.DATE = TABLEA.DATE
GROUP BY TABLEA.DATE

OUTPUT:
IUEUD     DATE     DATAA      DATAB
(empty)  (empty)   150       (emtpy)
4444     02        98        CORN
4444     03        78        GRAPES
(empty)  (empty)   55        (empty)

</div>
  • 写回答

4条回答 默认 最新

  • dongshanyan0322 2018-02-15 17:24
    关注

    If you specify in your select from which table the query should pull from then is should work as expected.

    SELECT DISTINCT A.IUEUD, A.DATE, A.DATAA, B.DATAB
    FROM TABLEA A
    LEFT JOIN TABLEB B
       ON TABLEB.IUEID = TABLEA.IUEID
       AND TABLEB.DATE = TABLEA.DATE
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 输入程序运行仿真后,烟雾值不实时检测,变成固定值
  • ¥15 lingo,求错误原因,这段代码哪里不对,求帮助!
  • ¥20 数据排序,可选择排序方向
  • ¥15 修改一下代码,考虑进程到达时间不同的情况
  • ¥15 华为nova10pro ,关闭热动热点用量记录
  • ¥15 帮我看看这是个啥题,带解题过程和结果,条件如下FCF = 290471.33 g1 = 15% r = 8% g2 = 4% n = 5
  • ¥15 edem模拟颗粒不显示或者生成失败
  • ¥15 Python代码编写
  • ¥15 php 将rtmp协议转hls协议,无法播放
  • ¥20 python代码编写