Why isn't this simple MySQL statement working?
Posted
by Clark
on Stack Overflow
See other posts from Stack Overflow
or by Clark
Published on 2010-04-06T23:21:59Z
Indexed on
2010/04/06
23:43 UTC
Read the original article
Hit count: 194
mysql
I am trying to match a user inputted search term against two tables: posts and galleries. The problem is the union all clause isn't working. Is there something wrong with my code?
$query = mysql_query("
SELECT * FROM posts WHERE title LIKE '%$searchTerm%'
OR author LIKE '%$searchTerm%'
OR location LIKE '%$searchTerm%'
OR excerpt LIKE '%$searchTerm%'
OR content LIKE '%$searchTerm%'
UNION ALL
SELECT * FROM galleries WHERE title LIKE '%$searchTerm%'
");
© Stack Overflow or respective owner