gpt4 book ai didi

php - mysql 将 3 个表中的选择与一个不同的列结合起来

转载 作者:行者123 更新时间:2023-11-29 12:21:00 24 4
gpt4 key购买 nike

我有 3 个类似的表格,其中有 1 个不同的列

id | user_id | post_id | other_id | favorite(tinyint) | date

id | user_id | post_id | other_id | like(tinyint) | date

id | user_id | post_id | other_id | comment(tinyint) | date

有没有办法返回 user_id = 1 且按日期排序的所有组合?

最佳答案

我想你想要这样的东西:

SELECT * FROM (
SELECT id, user_id, post_id, other_id, 'favorite' as type, date FROM table1
UNION
SELECT id, user_id, post_id, other_id, 'like' as type, date FROM table2
UNION
SELECT id, user_id, post_id, other_id, 'comment' as type, date FROM table3
) AS t ORDER BY date

关于php - mysql 将 3 个表中的选择与一个不同的列结合起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28999071/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com