VFP9- SQL with UNION

2008-07-23 Thread Sytze de Boer
Folk, I'm stuck

I'm trying to extract data from 3 seperate tables as follows
Select date,stockcode,stktype,invnum,SUM(qty) ,sell,desc, H as SRCE From
winhst  Where stktype=333 UNION ;
Select date,stockcode,stktype,invnum,SUM(qty) ,sell,desc, J as SRCE From
wintime Where stktype=333 UNION ;
Select date,stockcode,stktype,invnum,SUM(qty) ,sell,desc, I as SRCE From
wininvs  Where stktype=333 GROUP BY stockcode ORDER BY stockcode Into Table
myfile

It works fine except I end up with 1 record instead of about 50 (the number
of stockcode)
i.e. it does not respect the ORDER by clause

If I do
Select date,stockcode,stktype,invnum,SUM(qty) ,sell,desc, I as SRCE From
wininvs Where stktype=333 GROUP BY stockcode ORDER BY stockcode Into Table
myfile
it works fine, but (obviously) it excludes the data from the first 2 tables

I must be doing something wrong but I can't figure what it is.

Can someone help ?

-- 
Regards
Sytze de Boer
Kiss Systems
Ph: 64-7-8391670, Mob:021 937611,
Skype: kissman2
www.kiss.co.nz


--- StripMime Report -- processed MIME parts ---
multipart/alternative
  text/plain (text body -- kept)
  text/html
---

___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


Re: VFP9- SQL with UNION

2008-07-23 Thread Paul Hill
On Wed, Jul 23, 2008 at 7:32 AM, Sytze de Boer [EMAIL PROTECTED] wrote:
 Folk, I'm stuck

 I'm trying to extract data from 3 seperate tables as follows
 Select date,stockcode,stktype,invnum,SUM(qty) ,sell,desc, H as SRCE From
 winhst  Where stktype=333 UNION ;
 Select date,stockcode,stktype,invnum,SUM(qty) ,sell,desc, J as SRCE From
 wintime Where stktype=333 UNION ;
 Select date,stockcode,stktype,invnum,SUM(qty) ,sell,desc, I as SRCE From
 wininvs  Where stktype=333 GROUP BY stockcode ORDER BY stockcode Into Table
 myfile

 It works fine except I end up with 1 record instead of about 50 (the number
 of stockcode)
 i.e. it does not respect the ORDER by clause

 If I do
 Select date,stockcode,stktype,invnum,SUM(qty) ,sell,desc, I as SRCE From
 wininvs Where stktype=333 GROUP BY stockcode ORDER BY stockcode Into Table
 myfile
 it works fine, but (obviously) it excludes the data from the first 2 tables

 I must be doing something wrong but I can't figure what it is.

 Can someone help ?

Just a thought: try UNION ALL

-- 
Paul


___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


RE: VFP9- SQL with UNION

2008-07-23 Thread Dave Crozier
Sytze,

Use Union all not union. The union on its own removes duplicate records.

Dave Crozier


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Sytze de Boer
Sent: 23 July 2008 07:32
To: profox@leafe.com
Subject: VFP9- SQL with UNION

Folk, I'm stuck

I'm trying to extract data from 3 seperate tables as follows
Select date,stockcode,stktype,invnum,SUM(qty) ,sell,desc, H as SRCE From
winhst  Where stktype=333 UNION ;
Select date,stockcode,stktype,invnum,SUM(qty) ,sell,desc, J as SRCE From
wintime Where stktype=333 UNION ;
Select date,stockcode,stktype,invnum,SUM(qty) ,sell,desc, I as SRCE From
wininvs  Where stktype=333 GROUP BY stockcode ORDER BY stockcode Into Table
myfile

It works fine except I end up with 1 record instead of about 50 (the number
of stockcode)
i.e. it does not respect the ORDER by clause

If I do
Select date,stockcode,stktype,invnum,SUM(qty) ,sell,desc, I as SRCE From
wininvs Where stktype=333 GROUP BY stockcode ORDER BY stockcode Into Table
myfile
it works fine, but (obviously) it excludes the data from the first 2 tables

I must be doing something wrong but I can't figure what it is.

Can someone help ?

-- 
Regards
Sytze de Boer
Kiss Systems
Ph: 64-7-8391670, Mob:021 937611,
Skype: kissman2
www.kiss.co.nz


--- StripMime Report -- processed MIME parts ---
multipart/alternative
  text/plain (text body -- kept)
  text/html
---

[excessive quoting removed by server]

___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


Re: VFP9- SQL with UNION

2008-07-23 Thread Garrett Fitzgerald
I thought of that, but they aren't dup records: he's adding the SRCE
column so the data in each query is different.

On Wed, Jul 23, 2008 at 03:21, Dave Crozier [EMAIL PROTECTED] wrote:
 Use Union all not union. The union on its own removes duplicate records.

 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
 Of Sytze de Boer

 I'm trying to extract data from 3 seperate tables as follows
 Select date,stockcode,stktype,invnum,SUM(qty) ,sell,desc, H as SRCE From
 winhst  Where stktype=333 UNION ;
 Select date,stockcode,stktype,invnum,SUM(qty) ,sell,desc, J as SRCE From
 wintime Where stktype=333 UNION ;
 Select date,stockcode,stktype,invnum,SUM(qty) ,sell,desc, I as SRCE From
 wininvs  Where stktype=333 GROUP BY stockcode ORDER BY stockcode Into Table
 myfile


___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


Re: VFP9- SQL with UNION

2008-07-23 Thread Ted Roche
On Wed, Jul 23, 2008 at 2:32 AM, Sytze de Boer [EMAIL PROTECTED] wrote:
 Folk, I'm stuck

 I'm trying to extract data from 3 seperate tables as follows
 Select date,stockcode,stktype,invnum,SUM(qty) ,sell,desc, H as SRCE From
 winhst  Where stktype=333 UNION ;
 Select date,stockcode,stktype,invnum,SUM(qty) ,sell,desc, J as SRCE From
 wintime Where stktype=333 UNION ;
 Select date,stockcode,stktype,invnum,SUM(qty) ,sell,desc, I as SRCE From
 wininvs  Where stktype=333 GROUP BY stockcode ORDER BY stockcode Into Table
 myfile


What is it you are trying to end up with? Three records of SRCE J, H,
and I for each stockcode or only one?

Non-aggregating fields have undefined values. Drop them or use
something like MAX() to make them aggregating.

Finally, try moving the GROUP BY into each statement. The MSDN
language reference seems to imply that.


-- 
Ted Roche
Ted Roche  Associates, LLC
http://www.tedroche.com


___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.