多表查询结果合并再操作

2018-11-27  本文已影响0人  比博
$sql = "SELECT * FROM
                  (SELECT {$field}, {$comment_type} AS `type`
                  FROM `tab_comment`
                  WHERE `type`=1
                    AND `status`=1
                    AND `status_show`=1
                    AND `account`='{$account}'
                  UNION ALL
                  SELECT {$field}, {$collect_type} AS `type`
                  FROM `tab_collect_game`
                  WHERE `status`=1
                    AND `account`='{$account}'
                  UNION ALL 
                  SELECT {$field}, {$down_type} AS `type`
                  FROM `tab_down_record`
                  WHERE  `user_account`='{$account}'
                  ) AS `t`
                ORDER BY `create_time` DESC 
                LIMIT {$m},{$n}";
        $data = $this->query($sql);
上一篇 下一篇

猜你喜欢

热点阅读