UNION / db에서 검색한거끼리 합치려면

김지원·2023년 9월 7일
0

SELECT resume_tb.
FROM resume_tb
JOIN user_tb ON resume_tb.user_id = user_tb.id
WHERE user_tb.username LIKE '%홍%'
UNION
SELECT resume_tb.

FROM resume_tb
WHERE title LIKE '%홍%';

select resume_tb.* from resume_tb join user_tb on resume_tb.user_id = user_tb.id where user_tb.username like '%홍%';

select resume_tb.* from resume_tb where title like '%홍%';

    @Query(value = "SELECT resume_tb.* " +
                    "FROM resume_tb " +
                    "JOIN user_tb ON resume_tb.user_id = user_tb.id " +
                    "WHERE user_tb.username LIKE %:username% " +
                    "UNION " +
                    "SELECT resume_tb.* " +
                    "FROM resume_tb " +
                    "WHERE title LIKE %:title% ", nativeQuery = true)
    List<Resume> findResumeByUsernameOrTitle(@Param("username") String username, @Param("title") String title);

당연히 셀렉트한거 컬럼 같고 생긴 모양이 같아야함

DISTINCT 안해도 중복 제거됨

profile
https://github.com/k7850

0개의 댓글

관련 채용 정보