「SQL」サブクエリにIN文を使用するサンプル

構文
select 項目名 from テーブル where 項目名 in (select 項目名 form テーブル where 条件式)

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
select
contactname
, address
, city
from
customers
where
contactname in (
select
contactname
from
customers
where
address like '%ser%'
)
select contactname , address , city from customers where contactname in ( select contactname from customers where address like '%ser%' )
select
  contactname
  , address
  , city 
from
  customers 
where
  contactname in ( 
    select
      contactname 
    from
      customers 
    where
      address like '%ser%'
  ) 

結果

ContactName Address City
Sven Ottlieb Walserweg 21 Aachen

SQL

Posted by arkgame