一、exists用法
- 1、用法
select id, name, age from test where exists(select 1 from test2 where test.id = test2.id)
- 2、""exists(xxx)""就表示括號里的語句能不能查出記錄,它要查的記錄是否存在。
因此"select 1"這里的 "1"其實是無關緊要的,換成"*"也沒問題,它只在乎括號里的數據能不能查找出來,是否存在這樣的記錄,如果存在,這條語句的where 條件成立。