同时对三个表进行模糊查询,字段必须相同,顺序也要相同
$limit = CommonConst::API_LIMIT;
$page = Request::post('page', 1);
$offset = ($page - 1) * $limit;
$sql = sprintf("SELECT * FROM (SELECT paper_id as id,title,orderby,cover,price,'paper' as type FROM table1 UNION SELECT id,title,orderby,cover,price,'video' as type FROM table2 UNION SELECT id,title,orderby,cover,price,'book' as type FROM table3) as a WHERE a.title LIKE '%%%s%%' ORDER BY a.orderby desc LIMIT %d OFFSET %d ", $keyword, $limit, $offset);
$items = Db::query($sql);