If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Conensing multiple queries into one.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-25-08, 14:02
aadwight aadwight is offline
Registered User
 
Join Date: Nov 2008
Posts: 4
Conensing multiple queries into one.

Hi.

This may be a pretty simple question, but I'm pretty new to DB2 and SQL. Let's say I have an ordered list of employee performance reports. These reports have an employee ID number, but no name. I want to query my EMPLOYEES table and retrieve the name that matches each ID. Right now, I'm doing this using a Java loop that executes a separate SELECT statement to retrieve each record. I feel like this is a horribly inefficient way to do things, and am hoping there is some way to pass an ordered list of parameters into a query and retrieve a similarly ordered result set. Suggestions?
Reply With Quote
  #2 (permalink)  
Old 11-25-08, 15:17
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by aadwight
Suggestions?
http://mysite.verizon.net/Graeme_Birchall/id1.html
Reply With Quote
  #3 (permalink)  
Old 11-25-08, 16:25
aadwight aadwight is offline
Registered User
 
Join Date: Nov 2008
Posts: 4
Quote:
Originally Posted by n_i
Thanks, that looks very useful...but I'm not sure which of those 450+ pages answers my question.
Reply With Quote
  #4 (permalink)  
Old 11-25-08, 16:37
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
I'd start with concepts. What you are after is called a join.
Reply With Quote
  #5 (permalink)  
Old 11-25-08, 16:50
aadwight aadwight is offline
Registered User
 
Join Date: Nov 2008
Posts: 4
I might have phrased my problem poorly. I actually might have asked the wrong question entirely.

What I actually have is an Oracle database with some data (performance reports), and a DB2 database with some other data (employee names). If there's a way to join those two tables, that would be exactly what I want to do. I thought this was impossible, but further research shows that I might have been mistaken. So, should I just look further into how to do that, or is there another possible solution?
Reply With Quote
  #6 (permalink)  
Old 11-25-08, 17:06
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Depending on what you are more comfortable with, you could set up a federated database (from the DB2 side) or a database link (from the Oracle side) to reach to the other database. Both these solutions require additional software: Websphere Information Integrator (or whatever it is called these days) or Oracle Heterogenous Services respectively.

As an alternative, you could use an MS Access database to pull data from both sources via ODBC.
Reply With Quote
  #7 (permalink)  
Old 11-25-08, 17:17
aadwight aadwight is offline
Registered User
 
Join Date: Nov 2008
Posts: 4
I was afraid you might say something like that.

I'll have to check tomorrow to see if I have any of that software. I'm afraid I don't have an MS Access database to play with, so that one's not going to happen. In the meantime, I have a few ideas about how I might be able to cut down on the number of DB2 calls from the Java side of things. Thanks for your help.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On