SELECT DISTINCT(cb.id),
	cb.customer_name,
	cb.en_customer_name,
	cb.customer_no,
	cb.customer_number,
	cb.modify_time,
	cb.STATUS,
	cb.risk_status,
	cb.risk_time,
	cm.is_read 
FROM
	customer_base_info cb
	LEFT JOIN customer_manager cm ON cb.id = cm.customer_id 
WHERE
	cm.STATUS = 1 
	AND cb.id = 427950 

1.方法一:使用distinct字段(是distinct后面的所有字段相同才会去重)

   使用distinct的时候需要注意一个问题,开始我是这么写的distinct(cb.id),以为是直接只是根据id来去重的,但是不是这样的,而是根据distinct后面的根据所有的字段不同,

2.方法二:使用group by

SELECT
	cb.id,
	cb.customer_name,
	cb.en_customer_name,
	cb.customer_no,
	cb.customer_number,
	cb.modify_time,
	cb.STATUS,
	cb.risk_status,
	cb.risk_time,
	cm.is_read 
FROM
	customer_base_info cb
	LEFT JOIN customer_manager cm ON cb.id = cm.customer_id 
WHERE
	cm.STATUS = 1 
	AND cb.id = 427950 
GROUP BY
	cb.id

 

Logo

更多推荐