联合查询 UNION ALL
时间:2009-07-20 来源:phpwzb
多个表 联合查询 UNION ALL汇总,(各表的字段数量、类型必须相同)
查询总数时,一定要在最后写个“别名”,否则不正确(我自己暂时这么叫,因为我也不知道原因)
select count(*) as total from (
SELECT order_id FROM `member_orders`
UNION ALL
SELECT id FROM `orders`
UNION ALL
SELECT id FROM `phone_orders`
) c
SELECT order_id,receiver_name,receiver_address FROM `member_orders` where order_id=10
UNION ALL
SELECT id,username,acceptadd FROM `orders` where id=10
UNION ALL
SELECT id,username,address FROM `phone_orders` where id=10
相关阅读 更多 +