Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL SELECT (*) with COUNT(*)
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00387199
Message ID:
00387320
Views:
17
>Hi Chuck,
>What about :
>
>SELECT MyTable.field1,MyTable.Field2,Count(Mytable.Field1) as cntField1 ;
>FROM table1 ;
>GROUP BY table.field1 ;
>INTO Cursor MyCursor
>
>Your solution is the "GROUP BY" clause
>
>>Is there a way to run an SQL SELECT and get ALL the rows of data and still get a COUNT(*)? I have tried this, but it looks like like I'm just getting the last row of data along with the count. TIA, Chuck.

This will actually give you a count based on the value in field1. If all the values in field1 are unique (i.e. primary key), you will get a count of 1 in cntField1. If they aren't unique, then you will get an count of all records with that value in cntField1 and the other fields will have the vales of the last record physically in the table with that value in field1.
Ex.
field2      field1
ABC         VALUE1
DEF         VALUE2
GHI         VALUE1

Results
field1      field2      cntField1
VALUE1      GHI         2
VALUE2      DEF         1
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Previous
Reply
Map
View

Click here to load this message in the networking platform