{"id":33,"date":"2006-07-11T14:57:15","date_gmt":"2006-07-11T14:57:15","guid":{"rendered":"http:\/\/thenoyes.com\/littlenoise\/?p=33"},"modified":"2006-12-12T17:18:23","modified_gmt":"2006-12-12T17:18:23","slug":"quoth-the-maven","status":"publish","type":"post","link":"https:\/\/thenoyes.com\/littlenoise\/?p=33","title":{"rendered":"Quoth the maven"},"content":{"rendered":"<p>Straight quotes can be used like backticks around aliases IN SOME CASES (as of 5.0.15, at least).  Observe:<\/p>\n<p><code>CREATE TABLE myTable (id int, someData int);<br \/>\nINSERT INTO myTable VALUES (1, 1), (1, 2), (1, 3), (2, 1), (2, 2);<\/code><\/p>\n<p>These three queries produce identical output:<\/p>\n<p><code>SELECT * FROM myTable GROUP BY id;<br \/>\nSELECT * FROM myTable GROUP BY `id`;<br \/>\nSELECT * FROM myTable GROUP BY 'id';<\/code><br \/>\n<!--more--><\/p>\n<p>Likewise, these three produce identical output:<\/p>\n<p><code>SELECT id AS theId FROM myTable;<br \/>\nSELECT id AS `theId` FROM myTable;<br \/>\nSELECT id AS 'theId' FROM myTable;<\/code><\/p>\n<p>Same with these nine:<\/p>\n<p><code>SELECT id AS theId FROM myTable GROUP BY theId;<br \/>\nSELECT id AS theId FROM myTable GROUP BY `theId`;<br \/>\nSELECT id AS theId FROM myTable GROUP BY 'theId';<br \/>\nSELECT id AS `theId` FROM myTable GROUP BY theId;<br \/>\nSELECT id AS `theId` FROM myTable GROUP BY `theId`;<br \/>\nSELECT id AS `theId` FROM myTable GROUP BY 'theId';<br \/>\nSELECT id AS 'theId' FROM myTable GROUP BY theId;<br \/>\nSELECT id AS 'theId' FROM myTable GROUP BY `theId`;<br \/>\nSELECT id AS 'theId' FROM myTable GROUP BY 'theId';<\/code><\/p>\n<p>Obviously, these two are different:<\/p>\n<p><code>SELECT DISTINCT id FROM myTable;     -- produces '1' and '2'<br \/>\nSELECT DISTINCT 'id' FROM myTable;     -- produces 'id'<\/code><\/p>\n<p>As are any queries that compare a straight-quoted value to some other field:<\/p>\n<p><code>SELECT id AS theId FROM myTable GROUP BY theId = 1;    -- two rows in result<br \/>\nSELECT id AS theId FROM myTable GROUP BY 'theId' = 1;    -- one row in result<\/code><\/p>\n<p>Please refrain from using this knowledge outside of stumping your colleagues with arcane MySQL trivia. I shudder to think what misfortune awaits the developer who deliberately uses straight quotes in this fashion.<\/p>\n<p>UPDATE: Behavior has changed in 4.1.22, 5.0.30, 5.1.13, see <a href='http:\/\/bugs.mysql.com\/bug.php?id=14019'>http:\/\/bugs.mysql.com\/bug.php?id=14019<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Straight quotes can be used like backticks around aliases IN SOME CASES (as of 5.0.15, at least). Observe: CREATE TABLE myTable (id int, someData int); INSERT INTO myTable VALUES (1, 1), (1, 2), (1, 3), (2, 1), (2, 2); These three queries produce identical output: SELECT * FROM myTable GROUP BY id; SELECT * FROM [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[6],"tags":[],"class_list":["post-33","post","type-post","status-publish","format-standard","hentry","category-gotchas"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2IBF1-x","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/33","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=33"}],"version-history":[{"count":0,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/33\/revisions"}],"wp:attachment":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}