var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: MySQL Query to find available premises
I have a problem with a MySQL query. I have two tables, shown below:
Table 1: PREMISES
Table 2: TENANTS
I am trying to do a query that will find any premises that are NOT occupied by a tenant.
I was using this code:
BUT this displays all the premises that are not the same as the prem_id in the tenants table and does this for each tenant creating duplicated results.
select p1.address, p1.size, p1.price FROM premises AS p1,
tenants AS p2 WHERE p1.prem_id != p2.prem_id
Can anyone help me fix this query?
Thanks in advance.
Last edited by squire; 01-26-05 at
you need a LEFT OUTER JOIN looking for unmatched rows (null in the right table join field)
yes, i realize it looks weird the first time you see it
FROM premises AS p1
join tenants AS p2
where p2.prem_id is null
THANK YOU very much. Your code worked perfectly! I have been learning SQL and was thinking it may have something to do with joins but I have no proper knowledge of how to use them. This will help me greatly.
Thank you again.