dou70260 2017-07-18 17:48
浏览 251
已采纳

MySQL从两个表中获取数据

Im having some issues getting the result I want from two tables

table #1: history

  customer_id  |  Action
 ------------------------
  217          |  buy
 ------------------------
  218          |  sell
 ------------------------
  219          |  hold
 ------------------------

 table #2: Customers

  customer_id    |  name
 ----------------------------
  217            |  Alan
 ----------------------------
  218            |  Jan
 ----------------------------
  219            |  Rick

I have a really long query now, but essentially I want to add to match the name with the amount. I tried this but it didn't work:

(SELECT action AS action FROM "history` LEFT JOIN ON " customer(customer_id=customer_id)`)

I'm not really familiar with doing queries so any help would be appreciated

  • 写回答

3条回答 默认 最新

  • dongzhan9100 2017-07-18 17:53
    关注

    It should be this:

    SELECT h.Action AS action
       FROM history h
       LEFT JOIN Customers c
       ON h.customer_id = c.customer_id
    

    You either need to specify the tables or create an alias with which to associate columns/data.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器