List:General Discussion« Previous MessageNext Message »
From:Brent Clark Date:March 30 2011 8:05am
Subject:` vs '
View as plain text  
Hiya

Im wondering if someone could help me understand this. If you look at my 
two queries below. By the ORDER BY one is using ` and the other ', as a 
result, if you do an explain you will see that the top query does a 
filesort, while the other does not.

Would anyone know why.

mysql> explain SELECT `Contact`.`id`, `Contact`.`name`, 
`Contact`.`surname`, `Contact`.`mobile`, `Contact`.`user_id`, 
`Contact`.`active`, `Contact`.`created` FROM `contacts` AS `Contact`   
WHERE `Contact`.`user_id` = 10203 AND `Contact`.`active` = '1'   ORDER 
BY `name` asc LIMIT 10;
+----+-------------+---------+------+---------------+------+---------+------+--------+-----------------------------+
| id | select_type | table   | type | possible_keys | key  | key_len | 
ref  | rows   | Extra                       |
+----+-------------+---------+------+---------------+------+---------+------+--------+-----------------------------+
|  1 | SIMPLE      | Contact | ALL  | NULL          | NULL | NULL    | 
NULL | 344709 | Using where; Using filesort |
+----+-------------+---------+------+---------------+------+---------+------+--------+-----------------------------+
1 row in set (0.00 sec)

mysql> explain SELECT `Contact`.`id`, `Contact`.`name`, 
`Contact`.`surname`, `Contact`.`mobile`, `Contact`.`user_id`, 
`Contact`.`active`, `Contact`.`created` FROM `contacts` AS `Contact`   
WHERE `Contact`.`user_id` = 10203 AND `Contact`.`active` = '1'   ORDER 
BY 'name' asc LIMIT 10;
+----+-------------+---------+------+---------------+------+---------+------+--------+-------------+
| id | select_type | table   | type | possible_keys | key  | key_len | 
ref  | rows   | Extra       |
+----+-------------+---------+------+---------------+------+---------+------+--------+-------------+
|  1 | SIMPLE      | Contact | ALL  | NULL          | NULL | NULL    | 
NULL | 344710 | Using where |
+----+-------------+---------+------+---------------+------+---------+------+--------+-------------+
1 row in set (0.00 sec)

Thanks
Brent
Thread
` vs 'Brent Clark30 Mar
  • Re: ` vs 'Simcha Younger30 Mar
  • Re: ` vs 'Mark Goodge30 Mar