gpt4 book ai didi

mysql - sql从另一个表中获取名称

转载 作者:行者123 更新时间:2023-11-29 00:17:29 25 4
gpt4 key购买 nike

我有两张 table

buy_sim (id_buy ,id_client,date_buy,total_sims)< br/>表客户(id_clientname_clientlastname_client年龄)

当我从 buy_sim 中选择 * 时,我得到类似的东西:

|id_buy | id_client | date_buy  | total_sim |

|1 | 10 |2014-02-20 | 3 |

|2 | 8 |2014-02-21 | 4 |

如何在查询中获取 client_name?我试过了
select *,name_cliente from buy_sim,clients
但结果不是预期的。

最佳答案

这个怎么样:

SELECT sim.*, client.name_client
FROM buy_sim As sim INNER JOIN clients As client
ON sim.id_client = client.id_client

这是基于以下假设:

  • id_client是它们之间的公共(public)字段
  • INNER JOIN 似乎是一个不错的选择,因为它将返回所有记录,其中 id_clientsim 表和 client< 之间是通用的

更多关于 MySQL JOINS

关于mysql - sql从另一个表中获取名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22469782/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com