gpt4 book ai didi

mysql - 两行后内连接不起作用?

转载 作者:行者123 更新时间:2023-11-30 01:12:42 24 4
gpt4 key购买 nike

这是我的查询,即使表格内容匹配,它也没有显示第三行。

SELECT shopcategory_idcategory_name 
FROM shopcategory
INNER JOIN category ON shopcategory_id=category_id;

结果:

 ================================================================
| shopcategory_id | shopcategory_shopid | category_name |
================================================================
| 1 | 1 | Gadgets |
| 2 | 2 | Analog Device |
================================================================

这是我的查询,显示它有 3 行

SELECT * FROM shopcategory;

结果:

===================================================================
| shopcategory_id | shopcategory_shopid | shopcategory_categoryid |
===================================================================
| 1 | 1 | 1 |
| 2 | 2 | 2 |
| 3 | 3 | 3 |
===================================================================

编辑:查询我的类别表

SELECT * category;

结果:

==============================================
| category_id | category_name |
==============================================
| 1 | Gadgets |
| 2 | Analog Device |
| 3 | Beauty |
| 4 | Keyboard |
| 5 | Instruments |
| 6 | Monitor |
| 7 | Chairs |
==============================================

最佳答案

您应该在此处使用LEFT JOIN,并为要加入的表添加别名,如下所示:

SELECT 
tableName1.shopcategory_id,
tableName1.category_name,
tableName2.category_id
FROM
tableName1 as tb1
LEFT JOIN
tableName2 AS tb2
ON
tb1.shopcategory_id = tb2.category_id
GROUP BY
tb1.shopcategory_id;

关于mysql - 两行后内连接不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19346570/

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