SELECT DISTINCT A.pid FROM tags C, entries A LEFT JOIN comments B ON A.pid = B.pid WHERE A.blog IN ('foo', 'bar') AND A.pid = C.pid AND ( C.tag = 'foo' OR C.tag = 'bar' OR A.title LIKE '%fffuuuu%' OR B.teext LIKE '%fffuuuu%' )