|
Home > Archive > Microsoft SQL Server forum > March 2006 > How can I do amalgamate 3 select queries and then get unique entries from the result
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How can I do amalgamate 3 select queries and then get unique entries from the result
|
|
|
| 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
| |
| markc600@hotmail.com 2006-03-07, 9:24 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...
|
|
|
|
|