{"id":5379,"date":"2014-03-30T21:11:28","date_gmt":"2014-03-30T21:11:28","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-query-order-to-asc-or-desc-when-column-format-is-varchar-collection-of-common-programming-errors\/"},"modified":"2014-03-30T21:11:28","modified_gmt":"2014-03-30T21:11:28","slug":"how-to-query-order-to-asc-or-desc-when-column-format-is-varchar-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-query-order-to-asc-or-desc-when-column-format-is-varchar-collection-of-common-programming-errors\/","title":{"rendered":"How to query order to asc (or desc) when column format is varchar-Collection of common programming errors"},"content":{"rendered":"<p>I have a table <code>product(ID, name, quanlity)<\/code> with quanlity is <code>varchar(55)<\/code><\/p>\n<p>With my data<\/p>\n<pre><code>1 | Iphone 3  | 7\n2 | Iphone 3S | 8\n3 | Iphone 4  | 79\n4 | Iphone 4S | 9\n5 | Iphone 5  | 10\n<\/code><\/pre>\n<p>And my query:<\/p>\n<pre><code>Select * From product order by quanlity DESC\n<\/code><\/pre>\n<p>But result can&#8217;t order quanlity, because quanlity is varchar, How to query sort exactly<\/p>\n<pre><code>    4 | Iphone 4S | 9\n    2 | Iphone 3S | 8\n    3 | Iphone 4  | 79\n    1 | Iphone 3  | 7    \n    5 | Iphone 5  | 10\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I have a table product(ID, name, quanlity) with quanlity is varchar(55) With my data 1 | Iphone 3 | 7 2 | Iphone 3S | 8 3 | Iphone 4 | 79 4 | Iphone 4S | 9 5 | Iphone 5 | 10 And my query: Select * From product order by quanlity DESC [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5379","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5379","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5379"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5379\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5379"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5379"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5379"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}