本文介绍了MySQL在查询中显示空结果-使用INNER JOIN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下查询:

SELECT services.name as Service, services.logo_name as Logo, packages.name as Package
FROM `client_services`
INNER JOIN services ON service_id = services.id
INNER JOIN packages ON packages.id = package_id
WHERE client_id = 1
ORDER BY services.sort_id

client_services ,我需要显示5个结果.其中2个对于package_id为NULL.当我运行查询时,它仅显示3个结果,这些结果的package_id均已设置.

Well in client_services I have 5 results that need to be shown. 2 of them are NULL for package_id. When I run the query, it only shows 3 results, the ones that have a set package_id.

如果没有软件包,我只希望它显示为空白,但是其余信息很重要,因此我仍然需要显示记录.

If there is no package, I just want it to show up blank, but the rest of the information is important so I still need the record to show.

我是否需要更改查询中的任何内容才能使其正常工作?

Do I need to change anything in my query to get that to work?

谢谢!

推荐答案

更改一行:

LEFT JOIN packages ON packages.id = package_id

这篇关于MySQL在查询中显示空结果-使用INNER JOIN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 20:14