dbTalk Databases Forums  

How can I do amalgamate 3 select queries and then get unique entries from the result

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss How can I do amalgamate 3 select queries and then get unique entries from the result in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Astra
 
Posts: n/a

Default How can I do amalgamate 3 select queries and then get unique entries from the result - 03-07-2006 , 08:08 AM






Hi All

Strange request I know, but could somebody give me pointers on how I can put
3 queries into 1 'thing' and then get only the unique entries from this
'thing'.

To explain, I'm using Excel/VBA/ODBC to query an SQL DB. The 3 queries
themselves aren't that complex and all return the same 2 fieldsets of stock
code and stock desc. Because these separate queries might bring back the
same stock code/description I need to amalgamate the data and then query
again to bring out only distinct stock values, eg:

Query 1 brings back:

stock code stock desc
IVP Invoice Paper
STP Statement Paper
KGC Keyboard Cover
etc... etc...

Query 2 brings back:

stock code stock desc
IVP Invoice Paper
BOB Back Pack
KGC Keyboard Cover
etc... etc...

Query 3 brings back:

stock code stock desc
KGC Keyboard Cover
3.5"D 3.5" Disks
etc... etc...

I need to produce 1 resultset that shows:
stock code stock desc
IVP Invoice Paper
BOB Back Pack
3.5"D 3.5" Disks
KGC Keyboard Cover
STP Statement Paper
etc... etc...
(all unique entries)

I'm currently just bringing back the 3 query results in Excel, but I'd like
to be able to do the above.

In light of I'm using Excel/VBA/ODBC on a PC, is it possible to do?

Thanks

Robbie






Reply With Quote
  #2  
Old   
markc600@hotmail.com
 
Posts: n/a

Default Re: How can I do amalgamate 3 select queries and then get unique entries from the result - 03-07-2006 , 08:17 AM






You should simply be able to UNION your
queries together. UNION will remove duplicates

SELECT [stock code],[stock desc]
FROM Tab1...
UNION
SELECT [stock code],[stock desc]
FROM Tab2...
UNION
SELECT [stock code],[stock desc]
FROM Tab3...


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.