ID有多条记录导致用于副表 连接查询时会出现重复

SELECT <strong>DISTINCT</strong>
    h.house_id AS id,
    title AS title,
    cover_image_url AS thumb,
    house_price AS price,
    unit_price AS unitPrice,
    house_size AS size,
    `house_city_proper` AS area,
    house_room AS chambers,
    house_hall AS halls,
    house_toilet AS toilets,
    `house_partition` AS businessZone,
    address AS address,
    total_floor AS storey,
    floor AS floor,
    `house_property` AS buildings,
    house_aspect AS orientation,
    h.`house_usage` AS type,
    's' AS tradeMode,
    modDate AS lastUpdated,
    0 AS sort
FROM
    `t_house_sold` h
        LEFT JOIN
    `t_promotion` p ON (h.`house_id` = p.`house_id`)
WHERE
    h.`house_area_id` = 66
        AND h.`house_usage` = 'xzl'
        AND `house_state` = 'PUB'
        AND delflag = 0
        AND house_agent_state = 'NORMAL'
        AND house_price != 0
ORDER BY `promotion_time` DESC , `modDate` DESC , `promotion_type` DESC
LIMIT 500

如果没有用DISTINCT   会出现复复数据。也可以算作是处理这种重复的一种方案。

类似于:A表

1   a

2   b

B表:

1   at

1   ac

2   bc

A LEFT JOIN B 

ID为1的就会出现两条记录


所以一般副表应有唯一记录,否则易出现重复记录。

方案一:表里不出现一对多

方案二:查询结果去重


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值