> For the complete documentation index, see [llms.txt](https://heunnajo.gitbook.io/jpa-2-api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://heunnajo.gitbook.io/jpa-2-api/4.-api/sql-where-in.md).

# SQL : WHERE 절의 IN 사용법

WHERE (일치하기 원하는 컬럼명) IN (조건1, 조건2, 조건3, ...)

![DB](https://690266786-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MevvVBGi1-NWjhdSHRP%2F-MfDGbEc3zexsJKmXddo%2F-MfDHca3LuP7BqbW6v5L%2FScreen%20Shot%202021-07-22%20at%209.56.49%20PM.png?alt=media\&token=bf045d84-f188-40cd-b2c6-d84e921fb2be)

```sql
SELECT user_possition_code, user_status, regist_time
FROM tb_usesr_m
WHERE user_position_code IN ('P001','P002','P004')
```

의미 : IN 뒤로 나열한 조건들 중 일치하는 row를 가져온다!!\
이 때, 나열한 조건들은 OR 조건으로 검색한다!!\
즉, 조건에 일치하는 모든 내용들을 가져온다!!

V5에서 IN 뒤의 조건은 orderIds(모든 orderId 컬렉션) 이다.\
따라서 JPQL문맥에서 OrderItem과 Item을 조인할 때 이 컬렉션에 해당하면 List\<OrderItemDTO> 컬렉션으로 반환한다!

\+ List\<OrderItemDTO> 컬렉션 자체를 foreach로 돌려도 되지만, Map으로 변환해서 메모리에 한꺼번에 올린다.\
**foreach를 돌 때마다 쿼리가 나가는 것이 아니라 id(key)에 해당하는 OrderItemDTO(value)를 가져온다!!**
