Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Records matching MAX(Date)
Message
De
16/08/2002 07:37:58
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
16/08/2002 06:18:31
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00690278
Message ID:
00690287
Vues:
18
>Hi
>
>Can I, in 1 SELECT statement, achieve the following:
>
>Table1 contains fields PK = Primary Key, FK = Foreign Key, Date = Date.
>
>I need to obtain the records from the table that have the highest date entry, do I need to select the dates first and then include those results in a sub-query in a 2nd Select?
>
>Any ideas?
>
>Thanks
>Kev

Kevin,
No you don't have to do 2 SQLs. max() returns just one record so you could use that as a scalar value in 'where'. ie:

where ddate = (select max(...) ...)

A sample that demonstrates this (from FoxyClasses tips) :
create cursor myGrouper (Ino i, ddate d, irec i)
for ix = 1 to 20
	insert into myGrouper ;
		values (int(rand()*5), date()-int(rand()*100), ix)
endfor
select * from myGrouper order by 1,2

* This one is the tip *
select * from myGrouper A where ddate = ;
(select max(ddate) from myGrouper B where a.ino = b.ino) ;
order by ino
First a cursor created. Ino represents the FK and irec represents PK. Records are inserted where ddate is random (dates for a particular ino are out of order).
First SQL (select * from myGrouper order by 1,2) is there just to show how would be the dates if listed in order.
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform