I need to convert the following two working requests into one request, but all I'm trying to just die from me for various reasons. My end result is to try to list all the software at hand and show which software is installed and which is not installed for the particular PC requested. For the installed software, list the name; otherwise, NULL is NULL. I tried some subselect operators in the where clause, which gave me the result without error, but not the correct 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 | ------------------
Program 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 look for ... (Installed and removed software on PC1)
--------------------------------- | Sotfware | pc_id | name | --------------------------------- | SW_a | 1 | PC1 | | SW_b | 1 | PC1 | | SW_c | NULL | NULL | | SW_d | NULL | NULL | ---------------------------------
I have listed the mysql and sql tags because I do not think this is important, but just in case, I use mysql.
source share