If one has a grouped result set. ie:
(result set)
Id (bigint), UserId (int), Field1 (varchar), Field2 (varchar) ============================================================= 1, 22, 'Job', 'Teacher' 2, 22, 'Car', 'Mustang' 3, 22, 'Age', '35' 4, 47, 'Job', 'Clerk' 5, 47, 'Car', 'Corolla' 6, 47, 'Age', '23' 7, 85, 'Job', 'Banker' 8, 85, 'Car', 'Volkswagon' 9, 85, 'Age', '44' How can one return a result set based on a unique column (in this case, UserId) and get Fields in a where clause based on specific case?
To Match This:
Id (bigint), UserId (int), Car (varchar), Job (varchar), Age (varchar) ====================================================================== 1, 22, 'Mustang', 'Teacher', '35' 2, 47, 'Corolla', 'Clerk', '23' 3, 85, 'Volkswagon', 'Banker', '44' I know this is bad database design, but I am working with an old application. I have tried union or joining based on a separate select query with no avail.
Any help is appreciate as I am not proficient in SQL.
idcolumn in your result makes no sense. You should remove it.