채택완료

중복되는 것들만 모두 나오게 하게

2020-04-16 (목) 10:53:42 1,898

제가 지금 하려는 거는 it_model 값이 중복으로 있는 것들만 모두 출력하려고 합니다.

그래서 

Copy
select *,  COUNT(*) AS nums
           $sql_common
           and it_model !='' GROUP BY it_model HAVING nums > 1
           $sql_order
           limit $from_record, $rows

이렇게 했더니 중복되는 애들 중에 하나만 나옵니다.

어떻게 바꾸면

it_model 값이 중복되는 애들이 모~두 나올까요?

|

답변 1개 / 댓글 5개

채택된 답변
+20 포인트

select * from $sql_common

and it_model in (

    select it_model 

    from $sql_common

    and it_model <> ''

    group by it_model

    having count(it_model) > 1

)

$sql_order

limit $from_record, $rows

-----------

 위와같이 변경해서 한번 실행해보시죠

답변에 대한 댓글 5개

해봤는데 안되네용 ㅠ흑 ㅠㅠ
저도 저런식으로 시도를 해봣엇는데 ㅠ
흑 ㅠ
@뜨악뜨악 $sql_common 이라는 변수가 아닌
합쳐진 쿼리를 보여줘보세요
select *, COUNT(*) AS nums
from g5_shop_item
where (1) and it_model !='' GROUP BY it_model HAVING nums > 1
order by it_id desc

입니다.
(limit 뒤에는 생략했습니다.)
@뜨악뜨악

제가 만들어드린 쿼리가 정상적으로 작동하는데요
참고로.. group by 에 * 하면 나오는게 제한됩니다.
서브쿼리로 풀어야 정상입니다.


SELECT * FROM g5_shop_item
where it_model IN (select it_model
from g5_shop_item
where it_model !=''
GROUP BY it_model
HAVING COUNT(*) > 1
)
order by it_id desc

이걸로 한번 확인해보세요
엇! 됩니다!
제가 뭔가 오타라던지 뭔가 이상이 있엇나봅니다!
감사합니다!!!!!

답변을 작성하려면 로그인이 필요합니다.