IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Help required for a SQL query


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
wineye

New User


Joined: 24 Mar 2005
Posts: 3

PostPosted: Tue Jun 12, 2007 7:50 am
Reply with quote

Please help me on the below query:

1. There are 2 tables T1 & T2 each with columns A1, B1, C1 and A2, B2, C2 respectively.
2. Need to match A1, B1, C1 with A2, B2, C2 respectively. If there is no match between them, then the query needs to fetch the results comparing C1 & C2.

Please let me know if this could be done. If yes, how?
Back to top
View user's profile Send private message
Santoshdorge

New User


Joined: 27 Jun 2006
Posts: 48
Location: Pune

PostPosted: Tue Jun 12, 2007 9:29 am
Reply with quote

Hi
Try this ...........

select t1.*,t2.*
from t1
,t2
where
a1<> a2
and b1<>b2
and c1 <> c2
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Jun 12, 2007 5:47 pm
Reply with quote

Hello,

Please explain how that query matches the A, B, and C columns. . . What i see refers to "not=" - where is the "match" . . . icon_confused.gif Then, there is the requirement that if A,B,C do not match, try for a match on C only.

Did you test this before posting it?
Back to top
View user's profile Send private message
deepak.vl

New User


Joined: 17 Feb 2007
Posts: 38
Location: Hyderabad

PostPosted: Tue Jun 12, 2007 7:02 pm
Reply with quote

I think the below query should do (If I understood your question correctly icon_smile.gif )

SELECT *
FROM T1, T2
WHERE (A1 = A2
AND B1 = B2
AND C1 = C2)
OR ((A1 <> A2
OR B1 <> B2)
AND C1 = C2)
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts Issue with EXEC CICS QUERY SECURITY c... CICS 6
Search our Forums:

Back to Top