gpt4 book ai didi

mysql - 使用 Mysql 中的查询连接具有多列的表

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

我需要加入表格,但无法真正理解网站上的内容。你能帮我吗?

我有 table

产品

ID / product_name / product_description / product_code /

用户

ID / username / username_id / password /

已结账

ID /product_name /product_des /username /username_id /checkedout_date / return_date /

如何从产品(产品名称/产品描述)和用户(用户名/用户名_id)加入 checkout

非常感谢。

最佳答案

连接表相当简单。我将让您继续学习,但以下是连接这些表格的方法,以便您有一个引用来更好地理解您正在学习的内容。

这个想法是,您只需要列出您的表(在本例中,我为每个表添加了任意别名 - cpu),并指定您想要内部还是外部联接,然后指定要联接的列。您联接两个表中具有相同值的列。例如,Checkedout 有一个 username_id,而 Users 表有一个 ID。在指定要连接的内容(包括 AND 和 OR)时,您可以使用在 WHERE 子句中使用的所有相同逻辑

select
*
from
Checkedout c
inner join Products p
on (c.product_name = p.product_name and c.product_des = p.product_description)
inner join Users u
on (c.username_id = u.ID)

关于mysql - 使用 Mysql 中的查询连接具有多列的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47461549/

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