Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Select records with Maximum date group by address
Message
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00705983
Message ID:
00705998
Views:
21
This message has been marked as a message which has helped to the initial question of the thread.
Hi Nadya,

I would try.
select upper(CCODE+TOWN+STREET+str(STNUM,4)+STNUMEXT+UNIT) ;
       as Address, * from (m.tcTableName) ;
	WHERE  upper(CCODE+TOWN+STREET+str(STNUM,4)+STNUMEXT+UNIT) + DTOS(date) in ( ;
       		SELECT Address + DTOS(maxdate) FROM curTemp)
I think, now you can combine two queries in one this way.

>Hi Sergey,
>
>I have a table with lots of fields. I need to select records with maximum date grouped by address. We may have records with the same address and same date (maximum), but different info in other fields (for instance, one record would represent a sale and another record would represent mortgage) and they both were quite recent.
>
>Here is the test program, I just wrote:
>tcTableName = getfile('dbf')
>lcFile = justfname(m.tcTableName)+"TempTest"
>select upper(CCODE+TOWN+STREET+str(STNUM,4)+STNUMEXT+UNIT) ;
>       as Address, max(date) as MaxDate from (m.tcTableName) ;
>       group by 1 into cursor curTemp
>
>select upper(CCODE+TOWN+STREET+str(STNUM,4)+STNUMEXT+UNIT) ;
>       as Address, * from (m.tcTableName) tbl ;
>       inner join curTemp on ;
>       upper(tbl.CCODE+tbl.TOWN+tbl.STREET+str(tbl.STNUM,4)+tbl.STNUMEXT+tbl.UNIT) = ;
>       curTemp.Address and tbl.Date = curTemp.MaxDate
>
>
>But I'm not sure, I get it right... I could not figure out to do it in one SQL, though it's not a goal (if it could not be done in 1 select, I can use multiple)
>
>
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform