I have two tables Users and UserAttributes in SQL DB.
Table have structure like
Out required is
My attempted query
Select * from (
Select u.UserId,u.Username,u.UserEmail,ua.objectName,ua.objectValue
from Users u join userAttribute on u.UserId=ua.UserId
where ua.objectName='city' or pv.objectName='phone')) results
PIVOT (count(UserId)
For objectName IN ([city],[phone])) As pivot_table;
Current output
Still it is an double entry also for the reason I am not aware the city and phone results are in 0 and 1 (boolean).
Please help getting the desired output.



from Userwill never work.USERis a reserved keyword in SQL Server. Are you actually using T-SQL? Images of data, also, really don't help us help you. This looks like you have denormalised data though.cityandphoneshould be 2 separate columns in your data, not 1. Or is this process so that you can fix your design? (I hope so).