如何解决sql中的重复id?

时间:2015-08-10 18:09:08

标签: mysql

SELECT DISTINCT `timeline_id` , `status_id`
FROM `timeline`,`status`
Where `timeline`.`user_id` = 1
ORDER BY `timeline`.`dates` DESC

输出

timeline_id  status_id
1                1
1                2
1                3
2                1
2                2 
2                3
3                1
3                2
3                3

1 个答案:

答案 0 :(得分:0)

如果您在tbl status中有字段user_id,请尝试以下操作:

SELECT DISTINCT `timeline_id` , `status_id`
FROM `timeline` LEFT JOIN`status`
ON `timeline`.user_id = `status`.user_id
Where `timeline`.`user_id` = 1
ORDER BY `timeline`.`dates` DESC