Unpivot using SQL
![Image](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhB1GSSj_EQ6DSVu3gTy6LcMfbXJdP6nw3K5S19ERw-tA-DG8yFaVQS52BoMVwEmpjv1D1L3hPWNZ67QO_C1YTbb69gScpyskiWXdGRPK1HiwGkBjdKWurY3O-PP1z3VXwCJKb2BDLj0X6R13UzwMIqgu_6xuZYmZcoFWdxUvU_ERG9Bc96geX6OA7V/w400-h69/Screenshot%202023-05-19%20174724.png)
When converting columns into rows in SQL, unpivoting is used, effectively converting wide format (i.e., data with many columns) into long format (i.e., data with fewer columns and more rows). The process of pivoting, which includes turning rows into columns, is the opposite of this. Here is the syntax of Unpivot in SQL: SELECT [column1], [column2], [column3] FROM ( SELECT [id], [column1], [column2], [column3] FROM [table_name] ) AS [source_table] UNPIVOT ( [value] FOR [column_name] IN ([column1], [column2], [column3]) ) AS [unpivot_table]; In this syntax: [column1] , [column2] , and [column3] are the columns you want to unpivot. [table_name] is the name of the table containing the data you want to unpivot. [id] is a column that uniquely identifies each row in the table. [value] is the name of the column that will contain the values that were previously in the unpivoted columns. [column_name] is the name of the column that will contain the original column names. [unpivot_ta