I have this query:
select top(2)
property_id_ref
,image_file
,property_name
from property_master a
inner join image_master b
on a.property_id=b.property_id_ref
inner join customer_master c
on a.customer_id=c.customer_id
When I execute it, I get the following result:
512 ~/propertyimg/3954493 id_1.jpg Commercial Land
512 ~/propertyimg/3954493.jpg Commercial Land
But I need the output distinct property_id_ref
with random image_file
from the property_id_ref
like this:
512 ~/propertyimg/3954493 id_1.jpg Commercial Land
513 ~/propertyimg/3119918 Id.jpg Residential Plot
For that I made a query like:
select top(2)
max(pm.property_name) as property_name
,max(im.property_id_ref) as property_id_ref
,CONVERT(varchar(5000), max( CONVERT(binary, im.image_file))) as image_file
from property_master pm
inner join image_master im
on pm.property_id=im.property_id_ref
inner join customer_master cm
on pm.customer_id=cm.customer_id
group by im.property_id_ref
So I got the same output as the one I expected. I want to know whether this is the right way to do it, or is there any other better way of doing the same thing?
I am using SQL Server 2005.