0

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

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         |
==============================================
4

1 回答 1

0

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

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;
于 2013-10-13T15:10:35.663 回答