This is your query:
SELECT b.title
FROM sltdb_cddir_content a, sltdb_cddir_categories b
WHERE b.title like '%".$searchg."%' AND b.parent_id=81
UNION
SELECT a.title
FROM sltdb_cddir_content a, sltdb_cddir_categories b
WHERE a.categories_id=b.id AND a.title like '%".$searchg."%' AND b.parent_id=81;
In the first subquery, the join to a
is unimportant. The values are never used. This seems to be an equivalent query:
SELECT b.title
FROM sltdb_cddir_categories b
WHERE b.title like '%".$searchg."%' AND b.parent_id = 81
UNION
SELECT a.title
FROM sltdb_cddir_content a join
sltdb_cddir_categories b
on a.categories_id = b.id
WHERE a.title like '%".$searchg."%' AND b.parent_id = 81;
If the purpose is to get all titles from the two tables where the corresponding parent_id
is 81 and the title matches the pattern, then this query looks reasonable.