 <p>Just add a dummy column with the source name:</p> <pre><code>$query = '(SELECT "item" as table, id,name FROM `item` WHERE `accepted` = '1' AND `name` LIKE '%".$search."%') UNION ALL (SELECT "category" AS table, id,name FROM `category` WHERE `name` LIKE '%".$search."%') UNION ALL (SELECT "store" AS table, id,name FROM `store` WHERE `accepted` = '1' AND `name` LIKE '%".$search."%') LIMIT 25 '; </code></pre>