Home > Database > Mysql Tutorial > How Can I Achieve UNPIVOT Functionality in Microsoft Access 2010?

How Can I Achieve UNPIVOT Functionality in Microsoft Access 2010?

Susan Sarandon
Release: 2025-01-11 16:31:46
Original
154 people have browsed it

How Can I Achieve UNPIVOT Functionality in Microsoft Access 2010?

Achieving UNPIVOT Functionality in Microsoft Access 2010

Microsoft SQL Server's UNPIVOT function efficiently reshapes data from a wide to a long format. While Access 2010 doesn't offer a direct UNPIVOT equivalent, we can effectively replicate its behavior using SQL.

Imagine a table with multiple attribute columns (like A, B, C) linked to different keys (Key 1, Key 2, Key 3). The objective is to restructure this data so each attribute-key pair occupies its own row.

A UNION ALL query provides a solution:

<code class="language-sql">SELECT ID, A, B, C, [Key 1] AS key_field
FROM tblUnpivotSource
UNION ALL
SELECT ID, A, B, C, [Key 2] AS key_field
FROM tblUnpivotSource
UNION ALL
SELECT ID, A, B, C, [Key 3] AS key_field
FROM tblUnpivotSource;</code>
Copy after login

This query merges data from each key column into a unified table. Each resulting row signifies an attribute-key pairing:

ID A B C key_field
1 x y z 3
2 x y z 57
1 x y z 199
2 x y z 234
1 x y z 452
2 x y z 452

It's important to note that situations with duplicate key values (such as "452" in the example) will generate multiple rows with identical keys.

The above is the detailed content of How Can I Achieve UNPIVOT Functionality in Microsoft Access 2010?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template