最も簡単な方法は、存在しないコード>を使用することです。 またはleftjoin :
select u.*
from users u left join
addresses a
on a.username = u.username and
a.city = 'Peoria'
where a.city is null;
左結合 すべてのレコードをユーザーに保持し、すべてのレコードをアドレスに保持します onと一致する 条件。この場合(都市名が onにあるため 条件)、都市に関する情報または NULLのいずれかを持つすべてのユーザーを返します 値。 where 句はNULLを選択します 値-一致しない値。
同等のは存在しません フォローする方が簡単かもしれません:
select u.*
from users u
where not exists (select 1
from addresses a
where a.username = u.username and
a.city = 'Peoria'
);