Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Show Null Results in Query - With INNER JOIN

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.

enter image description here

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

Thanks!

like image 921
Drew Avatar asked Jan 19 '23 08:01

Drew


1 Answers

change one line:

LEFT JOIN packages ON packages.id = package_id 
like image 164
Avo Muromägi Avatar answered Jan 26 '23 00:01

Avo Muromägi