John Fox
John Fox

Reputation: 21

MySQL query returning records that match but also ones that do not

I'm using the standard LAMP environment. I've written a MySQL query which seems to works except for the fact that it returns results that don't fit the condition, as well as results that do.

$sql = "SELECT items.code, cats.cat_name, cats.id
        FROM items, cats
        WHERE cats.cat_name LIKE concat('%', items.code, '%') ";

The result that is retuned incudes all the matching records (items.code & cats.cat_name) but further down the retreived results it also shows the cat_names that do not match.

Upvotes: 0

Views: 88

Answers (1)

guest
guest

Reputation: 11

I guess that there is at least one row in items where code is null or an empty string. All cats rows will be joined with such a row in items.

Upvotes: 1

Related Questions