多表关联查询,对于副表怎么才能获取到MAX(t_track.t_id)对应的一条数据?
代码如下,查询结果,t_track.t_content,t_track.t_dateline这两个字段得出的数据都对不上MAX(t_track.t_id)的那条数据,应该怎么改呢?只用一条语句解决问题。在线等。。。
SELECT t_sales.t_id,t_sales.t_company, MAX(t_track.t_id) as track_id,t_track.t_content,t_track.t_dateline...
完整的语句:
SELECT
`t_sales`.`t_id`,
`t_sales`.`t_company`,
`t_sales`.`t_fenlei`,
`t_sales`.`t_tel`,
`t_sales`.`province`,
`t_sales`.`city`,
MAX(t_track.t_id) as track_id,
`t_track`.`t_content`,
`t_track`.`t_dateline`,
`t_city_1`.`city_name`,
`t_user`.`t_realname`
FROM `t_sales`
right join `t_track`
ON t_sales.t_id = t_track.t_sale_id
left join `t_city_1` ON t_sales.t_city = t_city_1.t_id
left join `t_user` ON t_sales.t_for_sale = t_user.t_id
WHERE (
(
(`t_track`.`t_uid`='214') AND (`t_user`.`t_id`='214')
) AND (
t_sales.t_id IS NOT NULL
)
) AND (
t_track.t_sale_id IS NOT NULL
)
GROUP BY `t_track`.`t_sale_id`
ORDER BY `t_track`.`t_dateline` DESC