mysql UNION query not working

Posted by kalpaitch on Stack Overflow See other posts from Stack Overflow or by kalpaitch
Published on 2010-03-13T14:26:05Z Indexed on 2010/03/13 14:35 UTC
Read the original article Hit count: 341

Filed under:

What am I doing wrong with this:

$sql = "SELECT * FROM content WHERE threadName LIKE '%$filter%' ORDER BY lastUpdated desc UNION SELECT * FROM content WHERE threadName NOT LIKE '%$filter%' ORDER BY lastUpdated desc";

The first statement before the UNION works well on its own, but this one above returns:

mysql_fetch_array() warning - supplied argument is not a valid MySQL result resource

Am I right in believing that UNION will not return duplicate entries, in which case the second SELECT statement doesn't need to have the NOT LIKE but will just return everything that wasn't listed in the first statement.

© Stack Overflow or respective owner

Related posts about mysql-query