K.Wayne K.Wayne - 3 months ago 11
MySQL Question

Why Mysql is returning wrong count of rows?

I have in database two information that matches with the names and the address. Instead of returning 2, this code is returning 21. Please see below;
(Table)-employees
id
name
address

$select = mysql_query("
SELECT *
FROM employees
WHERE name LIKE '%John%'
OR name LIKE '%Johanson%'
AND address='Streetford End'
");
$count = mysql_num_rows($select);
echo $count

Answer

This might be helpful:

SELECT * FROM employees WHERE (name LIKE '%John%' OR name LIKE '%Johanson%')
  AND address='Streetford End'