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.