Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Unions in SQL Select
Message
From
12/07/2004 19:24:24
John Tomblin
Service Station Systems, Inc.
San Jose, California, United States
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Unions in SQL Select
Miscellaneous
Thread ID:
00923488
Message ID:
00923488
Views:
56
I have two identical tables, one for jobs we are currently working on called OpenJobs and another containing invoiced jobs called DoneJobs.

There are many times when I need to get the total number of jobs that match some criteria from both tables. In the following example, I simply need the total number of jobs within a date range:

select cnt(Job) as Jobs from OpenJobs;
where between(GetJob("MaxDate", Job), BDate, EDate) and !deleted();
union all select cnt(Job) as Jobs from DoneJobs;
where between(GetJob("MaxDate", Job), BDate, EDate) and !deleted();
group by 1;
into cursor JobTot

I am trying to get a single record with the total number of jobs. The group by clause here is illegal. You can't group by an aggragate column. So I add an additional field to both selects: "X" as X and group by that column. It produces two records one from OpenJobs and one from DoneJobs.

What syntax can I use to get one record with the total of both tables?
Next
Reply
Map
View

Click here to load this message in the networking platform