Java查询租房信息表,一个可能一天会发两到五条重复信息,如何实现查询时去重

小刘
  • 526

希望从tenant_message表中查询租房信息,但是有的用户会一天发两到三条重复信息,希望可以在查询数据库时做一个去重,查询200条不同的数据,请问如何才能实现?

<sql id="Base_Column_List">
      title, userID, rental, address, update_time, create_time,
      rental_number, house_thumbnails, image_path, deposit,
      rentForm, house_area
    </sql>

<select id="selectTenantMessageV2" resultType="TenantMessage">
        SELECT
        tm.id, <include refid="Base_Column_List" />, tme.app_image_path,
        house_longitude, house_latitude
        FROM tenant_message tm
        LEFT JOIN tenant_message_extend tme
        ON tm.id = tme.tid
        <choose>
            <when test="sort=='ASC'">
                ORDER by id ASC limit #{offset}, #{limit}
            </when>
            <otherwise>
                ORDER by id DESC limit #{offset}, #{limit}
            </otherwise>
        </choose>
    </select>
SELECT
        tm.id, title, userID, rental, address, update_time, create_time,
      rental_number, house_thumbnails, image_path, deposit,
      rentForm, house_area, tme.app_image_path,
        house_longitude, house_latitude
        FROM tenant_message tm
        LEFT JOIN tenant_message_extend tme
        ON tm.id = tme.tid
        ORDER by id ASC limit 0, 200
回复
阅读 368
1 个回答

可以对关键字段做一个 hash,放 redis,表中也存在这么一个字段

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏