两张表结构
CREATE TABLE `t1` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`t1_name` char(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
`create_time` int(11) UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
CREATE TABLE `t2` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`t2_name` char(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
`create_time` int(11) UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
利用as将查询字段设置为一致 然后UNION ALL以后再order by 多张表依次类推
select id,t1_name as `name`,create_time,'t1' as table_name from t1
UNION ALL
select id,t2_name as `name`,create_time,'t2' as table_name from t2
ORDER BY create_time DESC
版权属于:本文是原创文章,版权归 吾梦小站 所有。
本文链接:https://nikm.cn/archives/55.html
本站所有原创文章采用 知识共享署名-非商业性使用 4.0 国际许可协议 进行许可。
您可以自由地转载和修改,但请务必注明文章来源并且不可用于商业目的。