Skip to content
Advertisement

PIVOT with 3 tables and JOIN without number values

Hope someone can help me or point me to the right direction. I’m more of a beginner in sql language.

I have 3 table users, dataTypes and usersData

I only managed to use join on three tables like this:

That gets all the entries for every single user like this and then repeating multiple times the same user id:

However I want for every data type to appear as a column and every row would have all entered user data. Something like this:

Looking on the internet, pivot is used to have row values as columns but the sql code is meant as aggregate (sum, min, max). Don’t know if this is the right approach with pivot or perhaps my tables are not properly organized.

Advertisement

Answer

I suspect that you want conditional aggregation to pivot your EAV model. The idea is:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement