I’m making a simple forum search for my site, which pulls data from 2 tables.
SELECT ft.id, ft.title, ft.date
FROM forum_topics ft
WHERE ft.title LIKE '%" .$search. "%' OR ft.body LIKE '%" .$search. "%'
UNION SELECT fr.topic, ft.title, fr.date
FROM forum_replies fr
INNER JOIN forum_topics ft ON fr.topic=ft.id
WHERE fr.body LIKE '%" .$search. "%'
ORDER BY date DESC
It’s pulling duplicates if it finds the term in both tables, how can I make it so it wont show duplicate records if the id of the result is the same.
You can try wrapping the
UNIONin another select, and add aGROUP BYon all columns: