{"id":3591,"date":"2024-08-23T08:05:34","date_gmt":"2024-08-23T00:05:34","guid":{"rendered":"https:\/\/five.co\/?p=3591"},"modified":"2024-08-23T08:05:51","modified_gmt":"2024-08-23T00:05:51","slug":"how-to-unpivot-in-mysql","status":"publish","type":"post","link":"https:\/\/preview-php85.dzine.org\/five\/blog\/how-to-unpivot-in-mysql\/","title":{"rendered":"How to Unpivot in MySQL: A Complete Guide"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Unpivot in MySQL<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In data analysis, it&#8217;s common to encounter data that is structured in a wide format, with values spread across multiple columns. While this format can be convenient for certain types of analysis, there are times when you need to reshape your data into a longer, more normalized format\u2014this process is known as &#8220;unpivoting.&#8221; In MySQL, unpivoting data is not as straightforward as it is in some other SQL databases, but with the right techniques, it can be done efficiently.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this article, we&#8217;ll explore how to unpivot data in MySQL, covering various methods and best practices. Whether you&#8217;re cleaning up data for analysis, preparing it for reporting, or just trying to make your database more flexible, understanding how to unpivot in MySQL will be a valuable skill.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n<div class=\"root-eb-toc-jlrm2 wp-block-essential-blocks-table-of-contents\"><div class=\"eb-parent-wrapper eb-parent-eb-toc-jlrm2 \"><div class=\"eb-toc-container eb-toc-jlrm2  eb-toc-is-not-sticky eb-toc-not-collapsible eb-toc-initially-not-collapsed eb-toc-scrollToTop style-1 list-style-none\" data-scroll-top=\"false\" data-scroll-top-icon=\"fas fa-angle-up\" data-collapsible=\"false\" data-sticky-hide-mobile=\"false\" data-sticky=\"false\" data-scroll-target=\"scroll_to_toc\" data-copy-link=\"false\" data-editor-type=\"\" data-hide-desktop=\"false\" data-hide-tab=\"false\" data-hide-mobile=\"false\" data-itemcollapsed=\"false\" data-highlight-scroll=\"false\"><div class=\"eb-toc-header\"><h2 class=\"eb-toc-title\">Table of Contents<\/h2><\/div><div class=\"eb-toc-wrapper \" data-headers=\"[{&quot;level&quot;:2,&quot;content&quot;:&quot;Unpivot in MySQL&quot;,&quot;text&quot;:&quot;Unpivot in MySQL&quot;,&quot;link&quot;:&quot;unpivot-in-mysql&quot;},{&quot;level&quot;:2,&quot;content&quot;:&quot;What Does Unpivot Mean?&quot;,&quot;text&quot;:&quot;What Does Unpivot Mean?&quot;,&quot;link&quot;:&quot;what-does-unpivot-mean&quot;},{&quot;level&quot;:2,&quot;content&quot;:&quot;Why Unpivot Data in MySQL?&quot;,&quot;text&quot;:&quot;Why Unpivot Data in MySQL?&quot;,&quot;link&quot;:&quot;why-unpivot-data-in-mysql&quot;},{&quot;level&quot;:2,&quot;content&quot;:&quot;Methods for Unpivoting Data in MySQL&quot;,&quot;text&quot;:&quot;Methods for Unpivoting Data in MySQL&quot;,&quot;link&quot;:&quot;methods-for-unpivoting-data-in-mysql&quot;},{&quot;level&quot;:3,&quot;content&quot;:&quot;Method 1: Using UNION ALL&quot;,&quot;text&quot;:&quot;Method 1: Using UNION ALL&quot;,&quot;link&quot;:&quot;method-1-using-union-all&quot;},{&quot;level&quot;:3,&quot;content&quot;:&quot;Method 2: Using a Stored Procedure&quot;,&quot;text&quot;:&quot;Method 2: Using a Stored Procedure&quot;,&quot;link&quot;:&quot;method-2-using-a-stored-procedure&quot;},{&quot;level&quot;:3,&quot;content&quot;:&quot;Method 3: Using Dynamic SQL&quot;,&quot;text&quot;:&quot;Method 3: Using Dynamic SQL&quot;,&quot;link&quot;:&quot;method-3-using-dynamic-sql&quot;},{&quot;level&quot;:2,&quot;content&quot;:&quot;Keep This In Mind&quot;,&quot;text&quot;:&quot;Keep This In Mind&quot;,&quot;link&quot;:&quot;keep-this-in-mind&quot;},{&quot;level&quot;:2,&quot;content&quot;:&quot;Common Use Cases for Unpivoting in MySQL&quot;,&quot;text&quot;:&quot;Common Use Cases for Unpivoting in MySQL&quot;,&quot;link&quot;:&quot;common-use-cases-for-unpivoting-in-mysql&quot;},{&quot;level&quot;:2,&quot;content&quot;:&quot;FAQs&quot;,&quot;text&quot;:&quot;FAQs&quot;,&quot;link&quot;:&quot;faqs&quot;},{&quot;level&quot;:2,&quot;content&quot;:&quot;Summary: Unpivot Data in MySQL&quot;,&quot;text&quot;:&quot;Summary: Unpivot Data in MySQL&quot;,&quot;link&quot;:&quot;summary-unpivot-data-in-mysql&quot;}]\" data-visible=\"[true,true,true,true,true,true]\" data-delete-headers=\"[{&quot;label&quot;:&quot;Unpivot in MySQL&quot;,&quot;value&quot;:&quot;unpivot-in-mysql&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;What Does Unpivot Mean?&quot;,&quot;value&quot;:&quot;what-does-unpivot-mean&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Why Unpivot Data in MySQL?&quot;,&quot;value&quot;:&quot;why-unpivot-data-in-mysql&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Methods for Unpivoting Data in MySQL&quot;,&quot;value&quot;:&quot;methods-for-unpivoting-data-in-mysql&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Method 1: Using UNION ALL&quot;,&quot;value&quot;:&quot;method-1-using-union-all&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Method 2: Using a Stored Procedure&quot;,&quot;value&quot;:&quot;method-2-using-a-stored-procedure&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Method 3: Using Dynamic SQL&quot;,&quot;value&quot;:&quot;method-3-using-dynamic-sql&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Keep This In Mind&quot;,&quot;value&quot;:&quot;keep-this-in-mind&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Common Use Cases for Unpivoting in MySQL&quot;,&quot;value&quot;:&quot;common-use-cases-for-unpivoting-in-mysql&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;FAQs&quot;,&quot;value&quot;:&quot;faqs&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Summary: Unpivot Data in MySQL&quot;,&quot;value&quot;:&quot;summary-unpivot-data-in-mysql&quot;,&quot;isDelete&quot;:false}]\" data-smooth=\"true\" data-top-offset=\"\"><div class=\"eb-toc__list-wrap\"><ul class=\"eb-toc__list\"><li><a href=\"#unpivot-in-mysql\">Unpivot in MySQL<\/a><li><a href=\"#what-does-unpivot-mean\">What Does Unpivot Mean?<\/a><li><a href=\"#why-unpivot-data-in-mysql\">Why Unpivot Data in MySQL?<\/a><li><a href=\"#methods-for-unpivoting-data-in-mysql\">Methods for Unpivoting Data in MySQL<\/a><ul class=\"eb-toc__list\"><li><a href=\"#method-1-using-union-all\">Method 1: Using UNION ALL<\/a><li><a href=\"#method-2-using-a-stored-procedure\">Method 2: Using a Stored Procedure<\/a><li><a href=\"#method-3-using-dynamic-sql\">Method 3: Using Dynamic SQL<\/a><\/li><\/ul><li><a href=\"#keep-this-in-mind\">Keep This In Mind<\/a><li><a href=\"#common-use-cases-for-unpivoting-in-mysql\">Common Use Cases for Unpivoting in MySQL<\/a><li><a href=\"#faqs\">FAQs<\/a><li><a href=\"#summary-unpivot-data-in-mysql\">Summary: Unpivot Data in MySQL<\/a><\/ul><\/div><\/div><\/div><\/div><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">What Does Unpivot Mean?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Unpivoting is the process of transforming columns into rows. For example, consider a table where sales data for different months is stored in separate columns:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Product<\/th><th>Jan_Sales<\/th><th>Feb_Sales<\/th><th>Mar_Sales<\/th><\/tr><\/thead><tbody><tr><td>A<\/td><td>100<\/td><td>120<\/td><td>130<\/td><\/tr><tr><td>B<\/td><td>90<\/td><td>110<\/td><td>105<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">After unpivoting, the data would look like this:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Product<\/th><th>Month<\/th><th>Sales<\/th><\/tr><\/thead><tbody><tr><td>A<\/td><td>Jan<\/td><td>100<\/td><\/tr><tr><td>A<\/td><td>Feb<\/td><td>120<\/td><\/tr><tr><td>A<\/td><td>Mar<\/td><td>130<\/td><\/tr><tr><td>B<\/td><td>Jan<\/td><td>90<\/td><\/tr><tr><td>B<\/td><td>Feb<\/td><td>110<\/td><\/tr><tr><td>B<\/td><td>Mar<\/td><td>105<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">This transformation allows for easier querying and analysis, especially when dealing with time series data or creating reports.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Why Unpivot Data in MySQL?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There are several reasons why you might want to unpivot your data in MySQL:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Normalization<\/strong>: Unpivoting helps normalize your data, making it easier to work with in relational databases.<\/li>\n\n\n\n<li><strong>Simplified Queries<\/strong>: After unpivoting, you can perform more straightforward queries, such as aggregations and filtering, without dealing with multiple columns.<\/li>\n\n\n\n<li><strong>Compatibility<\/strong>: Many analytics tools and reporting platforms prefer data in a long format, which makes unpivoting necessary for integration.<\/li>\n\n\n\n<li><strong>Data Analysis<\/strong>: When analyzing trends, having data in a long format is often more intuitive and easier to manipulate.<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Methods for Unpivoting Data in MySQL<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">While MySQL does not have a built-in <code>UNPIVOT<\/code> function like some other databases, you can achieve the same result using a combination of SQL functions and techniques. Here are some of the most common methods.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Method 1: Using <code>UNION ALL<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The most straightforward way to unpivot data in MySQL is by using the <code>UNION ALL<\/code> operator. This method involves selecting each column separately and combining them into a single result set.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"SELECT Product, 'Jan' AS Month, Jan_Sales AS Sales\nFROM sales\nUNION ALL\nSELECT Product, 'Feb' AS Month, Feb_Sales AS Sales\nFROM sales\nUNION ALL\nSELECT Product, 'Mar' AS Month, Mar_Sales AS Sales\nFROM sales;\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">SELECT<\/span><span style=\"color: #ABB2BF\"> Product, <\/span><span style=\"color: #98C379\">&#39;Jan&#39;<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">AS<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">Month<\/span><span style=\"color: #ABB2BF\">, Jan_Sales <\/span><span style=\"color: #C678DD\">AS<\/span><span style=\"color: #ABB2BF\"> Sales<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">FROM<\/span><span style=\"color: #ABB2BF\"> sales<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">UNION ALL<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">SELECT<\/span><span style=\"color: #ABB2BF\"> Product, <\/span><span style=\"color: #98C379\">&#39;Feb&#39;<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">AS<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">Month<\/span><span style=\"color: #ABB2BF\">, Feb_Sales <\/span><span style=\"color: #C678DD\">AS<\/span><span style=\"color: #ABB2BF\"> Sales<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">FROM<\/span><span style=\"color: #ABB2BF\"> sales<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">UNION ALL<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">SELECT<\/span><span style=\"color: #ABB2BF\"> Product, <\/span><span style=\"color: #98C379\">&#39;Mar&#39;<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">AS<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">Month<\/span><span style=\"color: #ABB2BF\">, Mar_Sales <\/span><span style=\"color: #C678DD\">AS<\/span><span style=\"color: #ABB2BF\"> Sales<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">FROM<\/span><span style=\"color: #ABB2BF\"> sales;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">This query will transform your wide data format into a long format by stacking the values of <code>Jan_Sales<\/code>, <code>Feb_Sales<\/code>, and <code>Mar_Sales<\/code> into a single column.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Pros:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Simple to understand and implement.<\/li>\n\n\n\n<li>Works well for small datasets.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Cons:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Can be cumbersome for tables with many columns.<\/li>\n\n\n\n<li>Performance may degrade with large datasets.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\"><strong style=\"background-color: rgb(69, 136, 216); color: rgb(241, 235, 218); font-size: calc(12px + 0.390625vw); font-weight: bold;\">Unpivot Data with a Rapid Database Builder<\/strong><\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">While understanding SQL and executing efficient queries isn&#8217;t too difficult, building a complete database often requires significant SQL knowledge. This is where rapid database builders like Five come into play.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Five provides a MySQL database for your application and generates an automatic UI, making it easier to interact with your data.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With Five, you can create interactive forms, dynamic charts, and comprehensive reports that are automatically generated based on your database schema.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Five also enables you to write custom JavaScript and TypeScript functions, providing additional flexibility to implement complex business logic, such as dynamically unpivoting data based on specific conditions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once your application is ready, Five simplifies deployment with just a few clicks, allowing you to deploy your MySQL-based application to a secure, scalable cloud infrastructure. This lets you focus on development while Five handles the intricacies of cloud deployment.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you\u2019re serious about using MySQL and efficiently managing data give Five a try.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/preview-php85.dzine.org\/five\/get-started\/\">Sign up for free access <\/a>to Five\u2019s online development environment and start building your MySQL web application today.<\/p>\n\n\n\n<div style=\"background-color: #001524;\"><hr style=\"height: 5px;\" \/>\n<pre style=\"text-align: center; overflow: hidden; white-space: pre-line;\"><span style=\"color: #f1ebda; background-color: #4588d8; font-size: calc(18px + 0.390625vw);\"><strong>Build Your Database In 3 Steps<\/strong><br \/><span style=\"font-size: 14pt;\">Start Developing Today<\/span><\/span><\/pre>\n<p style=\"text-align: center;\"><a href=\"https:\/\/preview-php85.dzine.org\/five\/get-started\" target=\"_blank\" rel=\"noopener\"><button style=\"background-color: #f8b92b; border: none; color: black; padding: 20px; text-align: center; text-decoration: none; display: inline-block; font-size: 18px; cursor: pointer; margin: 4px 2px; border-radius: 5px;\"><strong>Get Instant Access<\/strong><\/button><br \/><\/a><\/p>\n<hr style=\"height: 5px;\" \/><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Method 2: Using a Stored Procedure<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">For more complex scenarios or when you need to unpivot data frequently, you can create a stored procedure to handle the transformation. This approach allows for more flexibility and reusability.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"DELIMITER $$\n\nCREATE PROCEDURE UnpivotSalesData()\nBEGIN\n    SELECT Product, 'Jan' AS Month, Jan_Sales AS Sales FROM sales\n    UNION ALL\n    SELECT Product, 'Feb' AS Month, Feb_Sales AS Sales FROM sales\n    UNION ALL\n    SELECT Product, 'Mar' AS Month, Mar_Sales AS Sales FROM sales;\nEND$$\n\nDELIMITER ;\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ABB2BF\">DELIMITER $$<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">CREATE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">PROCEDURE<\/span><span style=\"color: #ABB2BF\"> UnpivotSalesData()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">BEGIN<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">SELECT<\/span><span style=\"color: #ABB2BF\"> Product, <\/span><span style=\"color: #98C379\">&#39;Jan&#39;<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">AS<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">Month<\/span><span style=\"color: #ABB2BF\">, Jan_Sales <\/span><span style=\"color: #C678DD\">AS<\/span><span style=\"color: #ABB2BF\"> Sales <\/span><span style=\"color: #C678DD\">FROM<\/span><span style=\"color: #ABB2BF\"> sales<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">UNION ALL<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">SELECT<\/span><span style=\"color: #ABB2BF\"> Product, <\/span><span style=\"color: #98C379\">&#39;Feb&#39;<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">AS<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">Month<\/span><span style=\"color: #ABB2BF\">, Feb_Sales <\/span><span style=\"color: #C678DD\">AS<\/span><span style=\"color: #ABB2BF\"> Sales <\/span><span style=\"color: #C678DD\">FROM<\/span><span style=\"color: #ABB2BF\"> sales<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">UNION ALL<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">SELECT<\/span><span style=\"color: #ABB2BF\"> Product, <\/span><span style=\"color: #98C379\">&#39;Mar&#39;<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">AS<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">Month<\/span><span style=\"color: #ABB2BF\">, Mar_Sales <\/span><span style=\"color: #C678DD\">AS<\/span><span style=\"color: #ABB2BF\"> Sales <\/span><span style=\"color: #C678DD\">FROM<\/span><span style=\"color: #ABB2BF\"> sales;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">END<\/span><span style=\"color: #ABB2BF\">$$<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">DELIMITER ;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">You can then call this procedure whenever you need to unpivot your data:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"CALL UnpivotSalesData();\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">CALL<\/span><span style=\"color: #ABB2BF\"> UnpivotSalesData();<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Pros:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Reusable and easy to maintain.<\/li>\n\n\n\n<li>Ideal for repetitive tasks.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Cons:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Requires more setup than a simple query.<\/li>\n\n\n\n<li>May be less flexible for on-the-fly transformations.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Method 3: Using Dynamic SQL<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If you have a table with a dynamic number of columns or if the column names are not known in advance, you can use dynamic SQL to unpivot your data. This method is more complex but provides maximum flexibility.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"SET @sql = NULL;\nSELECT GROUP_CONCAT(DISTINCT\n    CONCAT(\n      'SELECT Product, ''', column_name, ''' AS Month, ', column_name, ' AS Sales FROM sales'\n    )\n  ) INTO @sql\nFROM information_schema.columns\nWHERE table_name = 'sales' AND column_name LIKE '%_Sales';\n\nSET @sql = CONCAT(@sql, ' ORDER BY Product');\nPREPARE stmt FROM @sql;\nEXECUTE stmt;\nDEALLOCATE PREPARE stmt;\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">SET<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@sql<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">NULL<\/span><span style=\"color: #ABB2BF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">SELECT<\/span><span style=\"color: #ABB2BF\"> GROUP_CONCAT(<\/span><span style=\"color: #C678DD\">DISTINCT<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #56B6C2\">CONCAT<\/span><span style=\"color: #ABB2BF\">(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">      <\/span><span style=\"color: #98C379\">&#39;SELECT Product, &#39;&#39;&#39;<\/span><span style=\"color: #ABB2BF\">, column_name, <\/span><span style=\"color: #98C379\">&#39;&#39;&#39; AS Month, &#39;<\/span><span style=\"color: #ABB2BF\">, column_name, <\/span><span style=\"color: #98C379\">&#39; AS Sales FROM sales&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    )<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  ) <\/span><span style=\"color: #C678DD\">INTO<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@sql<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">FROM<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #D19A66\">information_schema<\/span><span style=\"color: #ABB2BF\">.<\/span><span style=\"color: #D19A66\">columns<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">WHERE<\/span><span style=\"color: #ABB2BF\"> table_name <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #98C379\">&#39;sales&#39;<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">AND<\/span><span style=\"color: #ABB2BF\"> column_name <\/span><span style=\"color: #C678DD\">LIKE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #98C379\">&#39;%_Sales&#39;<\/span><span style=\"color: #ABB2BF\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">SET<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@sql<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">CONCAT<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #E06C75\">@sql<\/span><span style=\"color: #ABB2BF\">, <\/span><span style=\"color: #98C379\">&#39; ORDER BY Product&#39;<\/span><span style=\"color: #ABB2BF\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">PREPARE stmt <\/span><span style=\"color: #C678DD\">FROM<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@sql<\/span><span style=\"color: #ABB2BF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">EXECUTE<\/span><span style=\"color: #ABB2BF\"> stmt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">DEALLOCATE<\/span><span style=\"color: #ABB2BF\"> PREPARE stmt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">This query dynamically generates the SQL needed to unpivot the data, making it suitable for tables where the structure may change over time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Pros:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Highly flexible and adaptable to changing table structures.<\/li>\n\n\n\n<li>Can handle a large number of columns efficiently.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Cons:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>More complex to implement.<\/li>\n\n\n\n<li>Requires knowledge of dynamic SQL.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Keep This In Mind<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Optimize for Performance<\/strong>: If you&#8217;re unpivoting large datasets, consider using indexes and optimizing your queries to reduce execution time.<\/li>\n\n\n\n<li><strong>Use Views<\/strong>: If you need to unpivot data frequently, consider creating a view that performs the unpivot operation. This can simplify your queries and make your code cleaner.<\/li>\n\n\n\n<li><strong>Test Your Queries<\/strong>: Always test your unpivot queries on a small subset of your data to ensure accuracy before running them on the entire dataset.<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Common Use Cases for Unpivoting in MySQL<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Sales Data Analysis<\/strong>: Unpivoting sales data by month, as shown in the examples, is a common use case. This allows for easier trend analysis and reporting.<\/li>\n\n\n\n<li><strong>Survey Data<\/strong>: If survey responses are stored in a wide format (e.g., one column per question), unpivoting the data can make it easier to analyze responses across different questions.<\/li>\n\n\n\n<li><strong>Financial Data<\/strong>: Unpivoting financial data, such as budgets or expenses across different departments, can help in creating more flexible financial reports.<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">FAQs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1. Does MySQL have a built-in <code>UNPIVOT<\/code> function?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>No, MySQL does not have a built-in <code>UNPIVOT<\/code> function. However, you can achieve the same result using techniques like <code>UNION ALL<\/code>, stored procedures, or dynamic SQL.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2. Is there a performance difference between using <code>UNION ALL<\/code> and dynamic SQL for unpivoting?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Yes, <code>UNION ALL<\/code> is generally simpler but may be less efficient for large datasets or tables with many columns. Dynamic SQL offers more flexibility and can handle larger datasets more efficiently, but it requires more complex queries.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3. Can I unpivot data directly in a MySQL view?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Yes, you can create a view that performs the unpivot operation. This is a good option if you need to unpivot data frequently and want to simplify your queries.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4. How can I handle NULL values when unpivoting data in MySQL?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>MySQL will preserve <code>NULL<\/code> values during the unpivot process. If you need to handle <code>NULL<\/code> values differently, consider using functions like <code>IFNULL<\/code> or <code>COALESCE<\/code> in your queries.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>5. What are the limitations of unpivoting data in MySQL?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>One limitation is that MySQL does not have a dedicated <code>UNPIVOT<\/code> function, so you need to use workarounds. Additionally, performance can be an issue with very large datasets or complex queries.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Summary: Unpivot Data in MySQL<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Unpivoting data in MySQL can be achieved using various methods, from simple <code>UNION ALL<\/code> queries to more advanced dynamic SQL. By understanding how to unpivot your data, you can make your database more flexible, simplify your queries, and prepare your data for analysis or reporting.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Unpivot in MySQL In data analysis, it&#8217;s common to encounter data that is structured in a wide format, with values spread across multiple columns. While this format can be convenient for certain types of analysis, there are times when you need to reshape your data into a longer, more normalized format\u2014this process is known as [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":3646,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_eb_attr":"","_uag_custom_page_level_css":"","footnotes":""},"categories":[21],"tags":[],"class_list":["post-3591","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"acf":[],"uagb_featured_image_src":{"full":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/08\/Five.Co-How-to-Unpivot-in-MySQL.png",1280,720,false],"thumbnail":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/08\/Five.Co-How-to-Unpivot-in-MySQL-150x150.png",150,150,true],"medium":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/08\/Five.Co-How-to-Unpivot-in-MySQL-300x169.png",300,169,true],"medium_large":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/08\/Five.Co-How-to-Unpivot-in-MySQL-768x432.png",768,432,true],"large":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/08\/Five.Co-How-to-Unpivot-in-MySQL-1024x576.png",1024,576,true],"1536x1536":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/08\/Five.Co-How-to-Unpivot-in-MySQL.png",1280,720,false],"2048x2048":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/08\/Five.Co-How-to-Unpivot-in-MySQL.png",1280,720,false]},"uagb_author_info":{"display_name":"Ryan Forrester","author_link":"https:\/\/preview-php85.dzine.org\/five\/author\/f1v5_ed9_au\/"},"uagb_comment_info":0,"uagb_excerpt":"Unpivot in MySQL In data analysis, it&#8217;s common to encounter data that is structured in a wide format, with values spread across multiple columns. While this format can be convenient for certain types of analysis, there are times when you need to reshape your data into a longer, more normalized format\u2014this process is known as&hellip;","_links":{"self":[{"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/posts\/3591","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/comments?post=3591"}],"version-history":[{"count":0,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/posts\/3591\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/media\/3646"}],"wp:attachment":[{"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/media?parent=3591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/categories?post=3591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/tags?post=3591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}