--- title: "Using PIVOT and UNPIVOT | Microsoft Docs" description: "Transact-SQL reference for PIVOT and UNPIVOT relational operators. Use these operators on SELECT statements to change a table-valued expression into another table." ms.date: "10/14/2019" ms.prod: sql ms.prod_service: "database-engine, sql-database, sql-data-warehouse, pdw" ms.reviewer: "" ms.technology: t-sql ms.topic: "language-reference" f1_keywords: - "PIVOT_TSQL" helpviewer_keywords: - "FROM clause, UNPIVOT operator" - "unpivoting tables" - "table pivoting [SQL Server]" - "UNPIVOT operator" - "crosstab query" - "PIVOT operator" - "rotating table-valued expressions" - "pivoting tables" - "FROM clause, PIVOT operator" - "rotating columns" ms.assetid: 24ba54fc-98f7-4d35-8881-b5158aac1d66 author: VanMSFT ms.author: vanto monikerRange: ">=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||=sqlallproducts-allversions||>=sql-server-linux-2017||=azuresqldb-mi-current" --- # FROM - Using PIVOT and UNPIVOT [!INCLUDE[tsql-appliesto-ss2008-all-md](../../includes/tsql-appliesto-ss2008-all-md.md)] You can use the `PIVOT` and `UNPIVOT` relational operators to change a table-valued expression into another table. `PIVOT` rotates a table-valued expression by turning the unique values from one column in the expression into multiple columns in the output. And `PIVOT` runs aggregations where they're required on any remaining column values that are wanted in the final output. `UNPIVOT` carries out the opposite operation to PIVOT by rotating columns of a table-valued expression into column values. The syntax for `PIVOT` provides is simpler and more readable than the syntax that may otherwise be specified in a complex series of `SELECT...CASE` statements. For a complete description of the syntax for `PIVOT`, see [FROM (Transact-SQL)](../../t-sql/queries/from-transact-sql.md). ## Syntax The following syntax summarizes how to use the `PIVOT` operator. ``` SELECT , [first pivoted column] AS , [second pivoted column] AS , ... [last pivoted column] AS FROM (