Please answer the question of a database statement: SELECT & nbsp; 'id' & nbsp;, & nbsp; 'time' & nbsp;, & nbsp; 'title' FROM & nbsp; 'think _ in' WHERE & nbsp; 'type' & nbsp; LIKE & nbsp; '$ k-%' U.
SELECT `id` , `time` , `title`
FROM `think_infor`
WHERE `type` LIKE '$k-%'
UNION ALL
SELECT `id` , `time` , `title`
FROM `think_infor2`
WHERE `type` LIKE '$k-%'
ORDER BY `time` DESC
LIMIT 0,6
You can use this statement to query the latest six pieces of information in Tables 1 and 2. But how can I determine which table the record returns?
Or is there any other method that can be implemented and you do not want to query it multiple times?
------ Solution --------------------
Can't you write it yourself?
SELECT `id` , `time` , `title`, 'think_infor' as tbl_name
FROM `think_infor`
WHERE `type` LIKE '$k-%'
UNION
SELECT `id` , `time` , `title`, 'think_infor2'
FROM `think_infor2`
WHERE `type` LIKE '$k-%'
ORDER BY `time` DESC
LIMIT 0,6
Added an output field tbl_name to differentiate data sources.
Change union all to union to avoid repeated records. If you do not add more sources, repeat them.