쿼리 질문입니다.

쿼리 질문입니다.

QA

쿼리 질문입니다.

답변 2

본문

 

select a.* , b.* , c.tr_brand ,a.idx as tidx from g5_tire_item a left join g5_tire_product b on (a.br_idx=b.idx) left join g5_tire_brand c on (b.br_idx=c.idx) where a.tr_use = '1' and b.br_use ='1' and c.tr_use = '1' and EXISTS( select * from g5_tire_item a where a.tr_inch = '245' and a.tr_height = '45' and a.tr_inch = '19') and ( a.tr_width = '245' ) and ( a.tr_height = '45' ) and ( a.tr_inch = '18' ) order by a.tr_card asc limit 0 , 30
 

해당쿼리가 오류는 없는데 값이 나오질 않네요...

 

EXISTS( select * from g5_tire_item a where a.tr_inch = '245' and a.tr_height = '45' and a.tr_inch = '19')

 

이부분을 제거하면 나오는데 해당조건의 값이있을 경우를 쿼리 해야 해서요...고수님들 답변을 기다립니다.

이 질문에 댓글 쓰기 :

답변 2

쿼리가 이상하네요 

exsits 절에는 a.tr_inch = '19'

그뒤에 and ( a.tr_inch = '18' )

 

뜯어보니 타이어 폭, 인치, 넓이 선택인거 같으네요 

 

exists 절 이후에는 다 날려 버리세요 

검색조건들이 중복됐고 동시에 만족할수 없습니다.

 

ps: 사족이지만 코드 좀 예쁘게 해서 보여주시면 분석이 편하겠네요 ^^

SELECT a.*, 
       b.*, 
       c.tr_brand, 
       a.idx AS tidx 
FROM   g5_tire_item a 
       LEFT JOIN g5_tire_product b 
              ON ( a.br_idx = b.idx ) 
       LEFT JOIN g5_tire_brand c 
              ON ( b.br_idx = c.idx ) 
WHERE  a.tr_use = '1' 
       AND b.br_use = '1' 
       AND c.tr_use = '1' 
       AND EXISTS(SELECT * 
                  FROM   g5_tire_item a 
                  WHERE  a.tr_inch = '245' 
                         AND a.tr_height = '45' 
                         AND a.tr_inch = '19') 
       AND ( a.tr_width = '245' ) 
       AND ( a.tr_height = '45' ) 
       AND ( a.tr_inch = '18' ) 
ORDER  BY a.tr_card ASC 
LIMIT  0, 30 

 

 

해당 테이블에 들어간 데이타를 예제로 알려주시면 좋을것 같네요. 

쿼리의 의도를 모르겠네요. 제생각엔 exists 안에 select 는 위의 테이블이랑 join하여 처리를 해야 하는데, 둘다 테이블 앨리어스를 같은 이름으로 해두었네요.

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
filter #php ×
전체 14,952
© SIRSOFT
현재 페이지 제일 처음으로