Click here to Skip to main content
15,890,670 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
SELECT distinct  loc.name,
             loc.imageurl,
              tu.userid,
             tu.fname,
             (SELECT TOP(1) [time]
              FROM   tblcheckin
              WHERE  userid = tf.followerid  and flag ='C'
              ORDER  BY [time] DESC) AS [time]
           ,  CONVERT(DECIMAL(16, 2), (dbo.DistanceBetween(  loc.latitude,loc.longitude,22.302647,73.190144))) as Distance
              FROM   tbl_follower tf
             INNER JOIN tbluser tu
                     ON tf.followerid = tu.userid
             LEFT OUTER JOIN tblgetlocation loc
                          ON loc.venueid = (SELECT TOP(1) locationid
                                            FROM   tblcheckin
                                            WHERE  userid = tf.followerid and flag ='C'
                                            ORDER  BY [time] DESC)
      where   tf.userid = 57 and tf.flag='YES'


Here My Output


Here is the output of my above query i have applied distinct but till the data are duplicated because of imageurl column.. so how can i remove duplicated record from result using userid. if userid repeated then delete record.

In my out put you can see,that the record with all data depends on userid, but i want to delete the record repeated with same userid if they are more then 1 then delete record of same userid having imageurl with 'ss1.4sql.net...'; –
Posted

Given below is query for deleting duplicate records. Modify the given below query according to your requirements -

SQL
DELETE
FROM TempCountry
WHERE CountryID NOT IN
	(
	SELECT MIN(CountryID)
	FROM TempCountry
	GROUP BY CountryCode
	)
 
Share this answer
 
Comments
Mas11 27-Nov-13 0:06am    
5*
Probably something like this

SQL
...Your Query

AND loc.imageurl NOT LIKE '%ss1.4sql.net%'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900