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
最佳答案
如果您在 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
关于mysql - 如何解决sql中重复的id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31926275/