MySQL \ join 2表产品和图像表

时间:2022-10-19 14:48:18

1.When we add record product details product table with image and without image.

1.当我们添加带有图像和没有图像的记录产品详细信息产品表时。

2.what is the query - product details added without image.

2.什么是查询 - 产品详细信息添加没有图像。

what is the query for fetching both table data when image not available of any one product.

当图像不可用于任何一个产品时,获取两个表数据的查询是什么。

Product table 
-----------------------------
ID | product_name | Size
-----------------------------
1  | TShirt 1      | S
2  | TShirt 2      | S
3  | TShirt 3      | S
4  | TShirt 4      | S
-----------------------------

Image table

图像表


ID | image_name | ref_id

1 | tshirt1.jpg | 1

2 | tshirt2.jpg | 2

3 | tshirt3.jpg | 3

3 个解决方案

#1


1  

LEFT OUTER JOIN.

LEFT OUTER JOIN。

Come on, this is basic knowledge easily found in any reference or tutorial on SQL.

来吧,这是在SQL的任何参考或教程中很容易找到的基本知识。

#2


0  

Select all Products where the Image is missing (NULL).

选择缺少图像的所有产品(NULL)。

SELECT * FROM Product INNER JOIN Image ON Product.ID = Image.ID WHERE image_name IS NULL;

SELECT * FROM Product INNER JOIN Image ON Product.ID = Image.ID WHERE image_name IS NULL;

#3


0  

1.SELECT Product_name,Size FROM Product_table, Image_Table ON
Product_table.ID=Image_table.ref_id WHERE image_name = IS NOT NULL;

1.SELECT Product_name,Size FROM Product_table,Image_Table ON Product_table.ID = Image_table.ref_id WHERE image_name = IS NOT NULL;

2.SELECT Product_name,Size FROM Product_table, Image_Table ON
Product_table.ID=Image_table.ref_id WHERE image_name IS NULL;

2.SELECT Product_name,Size FROM Product_table,Image_Table ON Product_table.ID = Image_table.ref_id WHERE image_name IS NULL;

#1


1  

LEFT OUTER JOIN.

LEFT OUTER JOIN。

Come on, this is basic knowledge easily found in any reference or tutorial on SQL.

来吧,这是在SQL的任何参考或教程中很容易找到的基本知识。

#2


0  

Select all Products where the Image is missing (NULL).

选择缺少图像的所有产品(NULL)。

SELECT * FROM Product INNER JOIN Image ON Product.ID = Image.ID WHERE image_name IS NULL;

SELECT * FROM Product INNER JOIN Image ON Product.ID = Image.ID WHERE image_name IS NULL;

#3


0  

1.SELECT Product_name,Size FROM Product_table, Image_Table ON
Product_table.ID=Image_table.ref_id WHERE image_name = IS NOT NULL;

1.SELECT Product_name,Size FROM Product_table,Image_Table ON Product_table.ID = Image_table.ref_id WHERE image_name = IS NOT NULL;

2.SELECT Product_name,Size FROM Product_table, Image_Table ON
Product_table.ID=Image_table.ref_id WHERE image_name IS NULL;

2.SELECT Product_name,Size FROM Product_table,Image_Table ON Product_table.ID = Image_table.ref_id WHERE image_name IS NULL;