SELECT * FROM alojamientos A INNER JOIN habitaciones B ON A.alojarid = B.alojarid and A.tipoid = 3 and B.pax_max=2;