MySql查詢兩張相同表,合併成一組資料,並區分資料的不同
阿新 • • 發佈:2020-08-18
SELECT * FROM ( SELECT `title`, 'img' AS TYPE, `id`, `orderid`, `posttime`, `content`, `description`, `checkinfo`, `linkurl`, `picurl`, `classid`FROM `#@__infoimg` WHERE parentid != 2 AND title LIKE '%$searchKey%' AND (classid = $CID OR parentstr LIKE '%,$CID,%') UNION ALL SELECT `title`, 'list' AS TYPE, `id`, `orderid`, `posttime`, `content`, `description`, `checkinfo`, `linkurl`, `picurl`, `classid`FROM `#@__infolist` WHERE checkinfo = TRUE AND title LIKE '%$searchKey%' AND (classid = $CID OR parentstr LIKE '%,$CID,%') ) AS tab ORDER BY tab.orderid DESC
要注意有可能在設定中
UNION 特別的方法不能使用,這些方法有肯能出現數據的洩露。所以會部分阻止使用。