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 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程