我使用下面的SQL从我的数据库表check_in
分组地址的多行显示最新的行只
$properties = $db->prepare("SELECT checkin_id, checkin_client_id, checkin_inventory_id, checkin_property_id, checkin_date, client_username, property_address_line_1, property_town, property_county, property_postcode, property_type, property_rooms, client_first_name, client_last_name, client_organisation_name, client_unique_id, checkin_passcode
FROM check_in ci
INNER JOIN properties pr
ON ci.checkin_property_id = pr.property_id
INNER JOIN clients cl
ON ci.checkin_client_id = cl.client_id
WHERE client_unique_id LIKE ? OR client_first_name LIKE ? OR client_username LIKE ? OR client_organisation_name LIKE ? OR property_address_line_1 LIKE ?")
工作正常获取信息,它带来的回所有符合搜索条件的行,但是,结果可能与地理位置链接的地址相同,但较新的日期明智(checkin_date
)。我只想显示每个地址的最近一行(property_address_line_1
),那么执行此操作的最佳方法是什么?
目前不在家,所以无法测试它。给我一个小时左右:) –
所有看起来不错,谢谢:) –
没问题,很高兴它的工作 –