ALTER PROCEDURE [dbo].[SP_STORED_PROCEDURE]
AS
BEGIN
SELECT
CUSTOMER_NAME,
CUSTOMER_PRODUCT_ID
FROM CUSTOMER
INNER JOIN PRODUCT ON PRODUCT_ID = CUSTOMER_PRODUCT_ID
END
我从产品表中选择数据。但是,如果CUSTOMER_PRODUCT_ID
为null
,则无法选择(请参阅)空数据。
如何查看所有数据?
或
任何帮助都将受到极大的赞赏。
感谢。
答案 0 :(得分:2)
ALTER PROCEDURE [dbo].[SP_STORED_PROCEDURE]
AS
BEGIN
SELECT
CUSTOMER_NAME,
CUSTOMER_PRODUCT_ID
FROM CUSTOMER
Left Outer JOIN PRODUCT ON PRODUCT_ID = CUSTOMER_PRODUCT_ID
END
使用Left outer join返回Customer表中包含product表中匹配行的所有数据,并在行不匹配时返回null