{"id":666,"date":"2012-11-12T07:01:08","date_gmt":"2012-11-12T07:01:08","guid":{"rendered":"http:\/\/codeatelier.wordpress.com\/?p=377"},"modified":"2016-09-10T13:41:20","modified_gmt":"2016-09-10T13:41:20","slug":"displaying-columns-as-rows","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/displaying-columns-as-rows\/","title":{"rendered":"Displaying columns as Rows"},"content":{"rendered":"<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nCREATE TABLE `fruits` (\r\n      `fruit_id` int(11) default NULL,\r\n      `fruit_name` varchar(255) collate latin1_general_ci default NULL\r\n    );\r\n\r\nINSERT INTO fruits(fruit_id, fruit_name) \r\n          VALUES (101, 'Mango'),\r\n                 (102, 'Apple'),\r\n                 (103, 'Orange'),\r\n                 (104, 'Pineapple'),\r\n                 (105, 'Lemon'),\r\n                 (106, 'Custard');\r\n<\/pre>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nSELECT row\r\n  FROM (SELECT fruit_id, CAST(fruit_id AS CHAR(255)) row\r\n          FROM fruits\r\n        UNION\r\n        SELECT fruit_id, CAST(fruit_name AS CHAR(255)) row\r\n          FROM fruits) s\r\n WHERE fruit_id = 101;\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<pre>\r\n 101\r\n Mango \r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>CREATE TABLE `fruits` ( `fruit_id` int(11) default NULL, `fruit_name` varchar(255) collate latin1_general_ci default NULL ); INSERT INTO fruits(fruit_id, fruit_name) VALUES (101, &#8216;Mango&#8217;), (102, &#8216;Apple&#8217;), (103, &#8216;Orange&#8217;), (104, &#8216;Pineapple&#8217;), (105, &#8216;Lemon&#8217;), (106, &#8216;Custard&#8217;); SELECT row FROM (SELECT fruit_id, CAST(fruit_id AS CHAR(255)) row FROM fruits UNION SELECT fruit_id, CAST(fruit_name AS CHAR(255)) row FROM fruits) s WHERE fruit_id&hellip; <a href=\"https:\/\/codethataint.com\/blog\/displaying-columns-as-rows\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-666","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/666","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=666"}],"version-history":[{"count":2,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/666\/revisions"}],"predecessor-version":[{"id":1570,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/666\/revisions\/1570"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=666"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=666"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}