SQL--查询两个字段相同的记录

1.如下,查询order_id和loan_lind两个字段相同的记录

select distinct a.order_preview_id, a.order_id, a.loan_kind

from ddk_order_preview_info a

join ddk_order_preview_info b

on a.order_preview_id != b.order_preview_id

where a.order_id = b.order_id and a.loan_kind = b.loan_kind;

 

=========================================================

SELECT    *
FROM
ddk_order_preview_info  a
WHERE
EXISTS (
SELECT
1
FROM
ddk_order_preview_info  b
WHERE
a.order_id = b.order_id
AND a.loan_kind = b.loan_kind
HAVING
COUNT (*) > 1
)

 

你可能感兴趣的:(java)