MySQL: NOT LIKE   

Aug 18th, 2011 // In: Php & MySQL // By: Comments 0

An important fact to know about the NOT LIKE is that it will cause your query to always return NULL/false, unless you add further argument that uses OR. Further argument that uses AND will not do the job of OR in the case. Below is a query that will work…

	$query = "SELECT *
	FROM " . $tablename . "
	WHERE ecipostid IS NOT NULL
	AND eciinuse NOT LIKE 'No' OR eciinuse IS NULL
	AND eciapplied > eciupdated;";

And here is a query that will not work, well it is the same query but with the OR eciinuse IS NULL removed…

	$query = "SELECT *
	FROM " . $tablename . "
	WHERE ecipostid IS NOT NULL
	AND eciinuse NOT LIKE 'No'
	AND eciapplied > eciupdated;";

The second query would return NULL and if you didn’t pick up on this information I’m giving you then you might spend some time looking over your records trying to establish why your not getting the query result you expect. Hence why I’m posting this.

Did this help? Please comment below, thank you for reading.

Tags: - -

Leave a Reply

You must be logged in to post a comment.