Click here to Skip to main content
15,905,238 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
Any SQL statement that I can use to remove duplicated records ?

I tried DISTINCT but its not helping

Here is my sql statement :

SQL
SELECT DISTINCT
                         Status_Legend.Status_Legend_ID, Status_Legend.Status_Legend_Desc, Status_Legend.Status_Legend_Severity, Station_Status_History.Status_Time
FROM            Status_Legend CROSS JOIN
                         Station_Status_History
WHERE        (Status_Legend.Status_Legend_Desc = @Status_Legend_Desc)
ORDER BY Status_Legend.Status_Legend_ID


Result :

CSS
1   good    7   2013-06-24 03:22:58 PM
1   good    7   2013-07-21 01:40:14 PM
1   good    7   2013-07-25 09:20:20 AM
1   good    7   2013-08-09 03:03:44 AM
1   good    7   2013-07-04 09:26:21 PM
1   good    7   2013-07-26 09:00:16 PM
1   good    7   2013-08-08 08:07:13 AM
1   good    7   2013-07-17 06:00:15 AM
1   good    7   2013-07-21 08:20:17 AM
1   good    7   2013-07-26 01:20:16 AM
1   good    7   2013-07-27 03:20:20 AM
1   good    7   2013-07-31 10:00:25 AM


Expected Result :

1 good 7 2013-07-27 03:20:20 AM

Only one RECORD

Thanks for your help in advance!
Posted
Comments
nandakishoreroyal 17-Mar-14 8:20am    
There is no duplicate records in your output, observe with care, all the records are different with respect to datetime.. your query is correct and output is also correct..
[no name] 17-Mar-14 8:21am    
The all are distinct records due to dateTime field. and tell why you need this specific 2013-07-27 03:20:20 AM data. Then you can put it with one more condition
Puseletso Michelle 17-Mar-14 8:32am    
thanks for you help I added more date on the other table that I join with, just needed to add a relationship to the two tables....thanks

1 solution

 
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