Pivoting Tables With MySQL

In this tutorial, we will cover pivoting tables with MySQL. Note you can use whatever language that comes with your DBMS that is SQL oriented such as SQL Server. You can think of pivoting tables as selecting unique values and assigning them to specific columns, hence pivoting the table. We will visit this question here on the Hackerrank website, a popular tool to prepare for interviews and or sharpen your skills with SQL and various other languages.

Link: https://www.hackerrank.com/challenges/occupations/problem


We are asked to pivot the occupation column in the OCCUPATIONS table. With each name sorted alphabetically and displayed underneath its corresponding occupation as an alias. We can do this in a few ways. I used the case function originally to select an individual occupation from the table.

Below is the query that passed the case test:

About the author


Hi, I'm Frank. I have a passion for coding and extend it primarily within the realm of Finance.

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *