I need help in writing a query.I have 4 tables which are related Works,WorkTypeProperties,WorkTypes,WorkProperties.
Now if i join all these tables i get the result using this query
select wp.WorkID,wp.WorkPropertyValue,IsValidated
from Works w
inner join (select WorkID,WorkPropertyValue,WorkTypePropertyID
from WorkProperties) wp
on w.WorkID=wp.WorkID
inner join (select WorkTypePropertyID,WorkTypeID
from WorkTypeProperties) wtp
on wtp.WorkTypePropertyID=wp.WorkTypePropertyID
inner join (select WorkTypeID
from WorkTypes
where DictionaryKey ='work_song') wt
on wt.WorkTypeID=wtp.WorkTypeID
Result is
workid workprop Isvalidated
2 la la song 0
2 234 0
2 2/8/2010 0
4 title 1
4 pop 1
4 3 1
4 2/22/2010 1
Now i want query for getting result like below
workid workprop1 workprop2 workprop3 workprop4 Isvalidated
2 la la song null 234 2/8/2008 0
4 title pop 3 2/22/2010 1
since i have max rows 4 in workid(2,4) i need to get 4 columns