Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Subquery
Message
From
10/08/2016 03:47:12
 
 
To
10/08/2016 03:33:46
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows 7
Network:
Windows XP
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01639295
Message ID:
01639301
Views:
56
>Sir I do not know where I am using GROUP BY in both parts of the UNION in the inner subquery.
>
>Please modify.

Tariq, please go back and take a very close look at your original SQL code that you posted. It had two GROUP BY statements on the inside subquery. The more recent code that you posted did not.

Regardless, let's look at this code, that's part of the UNION, from your most recent post.


SELECT distinct(acc_code) as acc_code ,max(acc_name) as acc_name, qty, cr_amount
from crsalp where substring(acc_code,1,2)='32' and type='P'


You're asking for an aggregation (max) of the acc_name, and you're also specifying other columns (acc_code, qty, cr_amount). When you aggregate a column, and you specify other columns in the SELECT without aggregating on them, you need to specify a GROUP BY.

Now...if your query is going against FoxPro tables, you *might* want to try adjusting the ENGINEBEHAVIOR to tap into older Fox behavior for aggregations, though I generally think it's better to make the syntax work with propery aggregation rules.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform