Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Get all records except the latest
Message
From
23/10/2008 16:40:31
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01356683
Message ID:
01356739
Views:
17
>>>Hi everybody,
>>>
>>>I have a complex query to get duplicates. I want to change all records (using SCAN/ENDSCAN) in the main table except for the latest record in each group. I can write a procedural code, but I'm wondering if there is a way to get them by SQL?
>>>
>>>I guess the procedural code would be simpler anyway.
>>>
>>>Thanks in advance.
>>Do you have unique id in each record? Can you show an example of the structure of your main table?
>
>Yes, I have the PK in each record.
>
>PK, FK, Date1, Date2, Flag
>
>I need to update all duplicates by FK and Flag = 1 to set flag = 0 except for the latest by Date1 and Date2. I already did it by procedural code, but curious if it's possible to get the records to update by SQL.
Another solution you can use something like
SELECT pk,fk,flag,date1,date2 FROM test WHERE Flag=1 AND DATE1 = (SELECT MAX(Date1) FROM Test T2 WHERE t2.fk=test.fk AND t2.flag=test.flag) AND DATE2 = (SELECT MAX(Date2) FROM Test T3 WHERE t3.fk=test.fk AND t3.flag=test.flag)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform