Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Select with high date
Message
From
19/09/2005 17:36:58
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
19/09/2005 14:34:36
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01050805
Message ID:
01051062
Views:
9
>>
>>select * from myTable t1 ;
>> where myDate = (select max(myDate) from myTable t2 where t1.Name == t2.Name)
>>
Cetin
>>
>
>
>I'm still down at VFP 6 so the following comments may not apply to you.
>
>I've had to do something like this, used the same logic, and found that the queries ran very slowly for a large (850K records) table.
>
>
>SELECT dw1.* FROM dwell dw1;
> WHERE dw1.agentcode = m.agentcode AND dw1.ctrl_num = m.ctrl_num;
>   AND dw1.dwedid = (SELECT MAX(dwedid) FROM dwell dw2;
>                      WHERE dw2.agentcode=dw1.agentcode AND dw2.ctrl_num=dw1.ctrl_num ;
>                        AND dw2.item_num=dw1.item_num);
>INTO CURSOR try1
>
>Rushmore optimization level for table dw2: none
>Rushmore optimization level for table e: none
>Using index tag Agentcode to rushmore optimize table dw1
>Using index tag Ctrl_num to rushmore optimize table dw1
>Rushmore optimization level for table dw1: full
>Rushmore optimization level for intermediate result: none
>
>The total time for the query was 52 seconds. The DWELL table has index tags on AgentCode, Ctrl_Num, Item_num, and DwEdid.
>
>By breaking it into two queries
>
>SELECT item_num,MAX(dwedid) AS dwedid FROM dwell;
> WHERE agentcode = m.agentcode AND ctrl_num = m.ctrl_num AND dwedid <= m.edid;
> GROUP BY item_num;
> INTO CURSOR curxxx
>
>SELECT dw1.* FROM dwell dw1, curxxx;
> WHERE dw1.agentcode = m.agentcode AND dw1.ctrl_num = m.ctrl_num;
>   AND dw1.dwedid = curxxx.dwedid and dw1.item_num=curxxx.item_num;
>INTO CURSOR try2
>
>Using index tag Agentcode to rushmore optimize table dwell
>Using index tag Ctrl_num to rushmore optimize table dwell
>Using index tag Dwedid to rushmore optimize table dwell
>Rushmore optimization level for table dwell: full
>Using index tag Agentcode to rushmore optimize table dw1
>Using index tag Ctrl_num to rushmore optimize table dw1
>Rushmore optimization level for table dw1: full
>Rushmore optimization level for intermediate result: none
>
>
>Query time was reduced to approximately half a second.
>
>As I mentioned, this is for VFP 6 and it may not be applicable in later versions

Rich,
Makes sense. While you've sample data to test it would you test this for me:
SELECT dw1.* FROM dwell dw1;
 WHERE dw1.agentcode = m.agentcode AND dw1.ctrl_num = m.ctrl_num;
   AND dw1.dwedid = (SELECT MAX(dwedid) FROM dwell dw2;
                      WHERE dw2.agentcode = m.agentcode AND dw2.ctrl_num = m.ctrl_num ;
                        AND dw2.item_num=dw1.item_num);
INTO CURSOR try1
TIA
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform