Is there any better way to make this query work? I’m looking for a more efficient solution, if there is one available.
SELECT `unitid`, `name` FROM apartmentunits WHERE aptid IN (
SELECT `aptid` FROM rentconditionsmap WHERE rentcondid = 4 AND condnum = 1
) AND aptid IN (
SELECT `aptid` FROM rentconditionsmap WHERE rentcondid = 2 AND condnum = 1
) ORDER BY name ASC
I think you want a self-join here. Join table
rentconditionsmapto itself, and indicate the conditions on either side of the join. Then join the results of that query intoapartmentunits.(Note: haven’t tested this, may require some tweaking…)