양치치의 아카이브

계층형쿼리 (Start with Connect by) 본문

코린이의 데이터베이스 일기장

계층형쿼리 (Start with Connect by)

넥타르 2022. 12. 23. 15:19

오라클에서만 사용가능한 편리한 쿼리

대댓글 메뉴 트리구조 등등 계층형 구조에 사용

 

start with ~ connect by prior ~  order silbings by ~

select * from table start with 최상위행 connect by 부모 자식관계 지정 prior 지정된 컬럼찾기 order siblings  계층형 쿼리에서 그룹별 정렬 수행

 

 

 

대댓글 예)

select * from 게시판테이블 where board_seq = 게시글번호 start with  boardview_re_level = 0 ( depth 레벨 0부터시작 ) connect by prior boardview_re_parent = boardview_seq (부모의 게시글번호를 찾아가기) order siblings by board_group_no desc; (댓글 그룹별로 정렬)

 

Comments