Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Select with Group by and Order by
Message
From
27/04/2010 08:16:43
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
26/04/2010 21:56:15
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 6 SP5
Miscellaneous
Thread ID:
01462119
Message ID:
01462153
Views:
58
>I'm trying to create a SQL Select statement that generates a query grouped on one field but ordered on another.
>
>The records look like this:
>
>name master_code master_ind
>ABC Company 001 Y
>ABC Comp 001 N
>ABC Cmpny 001 N
>DEF Comp 002 N
>DEF Cmpny 002 N
>DEF Company 002 Y
>
>I only want the resulting set to include the name field that has the master_ind = "Y" when grouped on the master_code.
>
>This doesn't work:
>
>select name, master_code ;
> from company ;
> group by master_code ;
> order by name, master_ind desc
>
>I'm trying to get the result set to look like this:
>
>name master_code
>ABC Company 001
>DEF Company 002
>
>I have to use VFP 6.0 SP 5 for this. Any ideas?
>
>Tim
Select * From myTable ;
  WHERE master_ind = 'Y' OR ;
  master_code In ;
  (Select master_code From myTable Having Count(*) = 1 Group By 1)
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