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 curl 命令调用正常,程序调用报 java.net.ConnectException: connection refused
  • ¥20 关于web前端如何播放二次加密m3u8视频的问题
  • ¥20 spring boot集成mqtt的使用问题
  • ¥15 使用百度地图api 位置函数报错?
  • ¥15 metamask如何添加TRON自定义网络
  • ¥66 关于川崎机器人调速问题
  • ¥15 winFrom界面无法打开
  • ¥30 crossover21 ARM64版本安装软件问题
  • ¥15 mymetaobjecthandler没有进入
  • ¥15 mmo能不能做客户端怪物