MySQL Show Null Results in Query - With INNER JOIN

依然范特西╮ 提交于 2019-12-10 17:06:15

问题


I have the following query:

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

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?

Thanks!


回答1:


change one line:

LEFT JOIN packages ON packages.id = package_id 


来源:https://stackoverflow.com/questions/8014631/mysql-show-null-results-in-query-with-inner-join

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!