두테이블 select 쿼리
본문
안녕하세요 정상 작동하는 쿼리인데
이 쿼리를 가지도 똑같은 내용의 두 가지 테이블을 조회하고 싶습니다
어떻게 소스를 변경하면 될까요?
도움 부탁드립니다.
g5_write_buy 테이블과 g5_write_ship 테이블을 함께 리스팅하고 싶습니다.
$sql = "select wr_datetime, wr_4, wr_5, wr_6, wr_11, wr_16, wr_18, wr_24, wr_29 from
g5_write_buy
where wr_18>0 and wr_30 = '출고완료' and wr_4 IS NOT NULL and wr_datetime between '2019-01-01 00:00:00' and '2019-01-31 23:59:00'
order by wr_datetime desc";
//echo $sql;
$query = sql_query($sql);
답변 2
full join으로 검색해 보세요
$sql = "select wr_3, wr_4, wr_5, wr_6, wr_11, wr_16, wr_18, wr_24, wr_29 from (select wr_3, wr_4, wr_5, wr_6, wr_11, wr_16, wr_18, wr_24, wr_29 from g5_write_ship
g5_write_ship
union all
select wr_3, wr_4, wr_5, wr_6, wr_11, wr_16, wr_18, wr_24, wr_29 from
g5_write_buy) as U
where U.wr_18 > 0 and U.wr_3 between '2019-01-01 00:00:00' and '2019-01-31 23:59:59'
order by U.wr_3 asc ";
해결했습니다. 감사합니다.
!-->
답변을 작성하시기 전에 로그인 해주세요.