Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combining results into one resultset (union join)

Status
Not open for further replies.

fcoomermd

Programmer
Nov 20, 2002
218
CA
Not sure how to do this...
Problem:
I have the results from two queries, and would like them to be combined in one resulset.
For example,
Query 1 return:
id,
startWeek
hours
employeeID
taskID

Query 2 returns:
dateUpdated
hours
employeeID


I would like the results to be combined like this
id
startWeek - dateUpdated
hours - hours
employeeID - employeeID
taskID

I tried doing a "Select into" for each query, specifing the same temp table...
Ideas? Thoughts?
Help would be appreciated...
Thanks
 
What do you want this result set to look like:

a. One Row contains data from both queries
b. Both query results are displayed 'stacked' on top of each other (in case of the second query, ID and taskID would be blank)

A wise man once said
"The only thing normal about database guys is their tables".
 
Code:
SELECT a.id, a.startWeek, b.dateUpdate, a.hours, b.hours as uphours, a.employeeID, a.taskID
FROM (sql for query1) a left outer join (sql for query2) b on a.empolyeeID = b.employeeID
This assumes queries are not saved, also the join may not be the one you want.
Good Luck,
djj
 
I figured it out...
select a, b, c, d from tableA
union all
select e, f, g, h from tableB

Thanks for the input guys and gals...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top