Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Group by error
Message
From
23/06/2003 10:12:33
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
23/06/2003 09:51:21
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
00802887
Message ID:
00802897
Views:
15
>I need to retrieve the pi_id for the latest expdate by pitype. in vfp 7 I would do:
>
>
>SET ENGINEBEHAVIOR 70
>SELECT ;
>	pi_id,;
>	pitype_id,;
>	MAX(expdate);
>	FROM PI ;
>	WHERE eqtype_id=2 AND equip_id=2246 ;
>	GROUP BY 2;
>	INTO CURSOR cc1
>
>
>in vfp 8 that gives me a group by error
>
>
>SET ENGINEBEHAVIOR 80
>SELECT ;
>	pi_id,;
>	pitype_id,;
>	MAX(expdate);
>	FROM PI ;
>	WHERE eqtype_id=2 AND equip_id=2246 ;
>	GROUP BY 1,2;
>	INTO CURSOR cc1
>
>
>works but gives me all records because pi_id is the unique primary key (which i AM AFTER)
>
>
>What to do?
>
>Peter
SELECT ;
	pi_id,;
	pitype_id,;
	expdate ;
	FROM PI t1 ;
	WHERE eqtype_id=2 AND equip_id=2246 ;
          and expdate = ;
         (select max(expdate) from pi t2 where t1.pitype_id = t2.pitype_id) ;
	INTO CURSOR cc1
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