I need to convert the following two working queries into a single query but everything I try just dies on me for various reasons. My end result is to try to list all software on hand, and show which software is installed and which is not installed for the specific PC being queried. For installed software, list the name, otherwise show NULL for the name. I've tried some sub-select statements in the where clause which gave me a result without an error, but not the right result. Any help is appreciated.
qry1
SELECT device_software.sw_id
FROM Software_device LEFT JOIN Device ON Software_device.d_id = Device.d_id
WHERE Device.d_id = 1;
qry2
SELECT Software.name, Software.sw_id, qry1.sw_id
FROM software LEFT JOIN qry1 ON software.sw_id = qry1.sw_id;
Device Table
------------------
| name | d_id |
------------------
| PC1 | 1 |
| PC2 | 2 |
| PC3 | 3 |
------------------
Software Table
------------------
| name | sw_id |
------------------
| SW_a | A |
| SW_b | B |
| SW_c | C |
| SW_d | D |
------------------
Software_Device Table (Many-to-many)
------------------
| d_id | sw_id |
------------------
| 1 | A |
| 1 | B |
| 2 | A |
| 2 | B |
| 2 | C |
------------------
Result Im looking for... (Installed AND uninstalled software on PC1)
---------------------------------
| Sotfware | pc_id | name |
---------------------------------
| SW_a | 1 | PC1 |
| SW_b | 1 | PC1 |
| SW_c | NULL | NULL |
| SW_d | NULL | NULL |
---------------------------------
I listed both mysql and sql tags because I don't think it matters, but just in case it does, i'm using mysql.