I have a database that has 16 tables, but only four are relevant to this. The database tracks different servers, the servers information (CPU, RAM, IP Address, etc) and the software it is running. The software and machines are related through a join table.
CREATE TABLE machsoftjt (
mid int(4) NOT NULL,
sid int(4) NOT NULL,
slid int(4) NOT NULL,
notes varchar(255) default NULL,
UNIQUE KEY mid (mid,slid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
mid is the machine’s id from the machines table, sid is the software’s id from the software table which contains the software’s name and software’s version, slid is the softwarelist id from the softlist table(a table with just lists the software being run and is used for unique constraint so that when software upgrades are performed I don’t have an entry for one machine running two different versions of the same software). So if I have machine1 (with a mid of 1) running Microsoft Word 2010 (with a sid of 1 and a slid of 1) and Adobe Photoshop 5 (with a sid of 2 and a slid of 2), the table would have
mid sid slid
1 1 1
1 2 2
I want to select from this table all machines that is running both Microsoft Word and Adobe Photoshop.
SELECT machines.machinename FROM (machines INNER JOIN machsoftjt ON
machines.mid=machsoftjt.mid) INNER JOIN software ON machsoftjt.sid=software.sid
WHERE machsoftjt.slid='1' AND machsoftjt.slid='2'
When I run this query, I do not get anything backWhen I run this query, I do not get anything back. And I am now stumped and can’t come up with anything else. All help would be greatly appreciated.
This calls for a self-join. Roughly:
To get software names, roughly:
You’ll probably have to alias the relevant columns from s1 and s2