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 > Query Problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-15-09, 14:12
cprash.aggarwal cprash.aggarwal is offline
Registered User
 
Join Date: Mar 2009
Posts: 24
Query Problem

I have 3 tables

X

OID PN

1 A
2 B
3 C

Y

OID EC

2 D
4 E
6 F

Z

OID_X OID_Y

1 2
3 4
3 6
5 2
5 6

OID_X REFERS TO OID IN TABLE X AND OID_Y REFERS TO OID IN TABLE Y

nOW, I WANT RESULT AS
PN EC

A D
B E
B F
C D
C F
WHICH IS SAME AS COMBINATION IN TABLE Z,

i TRIED THESE BUT NONE IS GIVING DESIRED RESULTS.

SELECT PN, EC FROM X, Y, Z WHERE Z.OID_X=X.OID AND Z.OID_Y=Y.OID

SELECT PN, EC FROM X, Y, Z WHERE (X.OID,Y.OID) IN (SELECT OID_X, OID_Y FROM Z)

PLEASE HELP

THANKS
Reply With Quote
  #2 (permalink)  
Old 03-15-09, 15:39
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
you have over-simplified your problem to the point where i believe that even you have lost track of the Xs and Ys

kindly rephrase your question
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-15-09, 22:54
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
The result
PN EC

A D
B E
B F
C D
C F

would be obtained by
Code:
------------------------------ Commands Entered ------------------------------
WITH X(OID, PN) AS (
VALUES
 (1, 'A')
,(2, 'B')
,(3, 'C')
)
,Y(OID, EC) AS (
VALUES
 (2, 'D')
,(4, 'E')
,(6, 'F')
)
,Z(OID_X, OID_Y) AS (
VALUES
 (1, 2)
,(3, 4)
,(3, 6)
,(5, 2)
,(5, 6)
)
SELECT pn, ec
  FROM x, y, z
 WHERE oid_x = x.oid * 2 - 1
   AND oid_y = y.oid
;
------------------------------------------------------------------------------

PN EC
-- --
A  D 
B  E 
B  F 
C  D 
C  F 

  5 record(s) selected.
But, I am not sure that is what you want.
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