On 30/03/2011 09:05, Brent Clark wrote:
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.
Because column names either need to be unquoted or enclosed in
backticks. If you put a string inside ordinary quotes (either single or
double) then it's treated as a string variable. And you can't sort by a
string variable.
As a demonstration, try these:
SELECT * FROM contacts LIMIT 10
SELECT * FROM `contacts` LIMIT 10
SELECT * FROM 'contacts' LIMIT 10
The first two will work. The third will fail, as you can't select from a
variable.
Alternatively, try this:
SELECT id FROM contacts LIMIT 10
SELECT `id` FROM contacts LIMIT 10
SELECT 'id' FROM contacts LIMIT 10
and all will be even more clear :-)
Mark
--
http://mark.goodge.co.uk
http://www.ratemysupermarket.com
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=arch...@jab.org