Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Help required for a SQL query

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Help required for a SQL query
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    Post subject: Re: Help required for a query
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

Site Director


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

PostPosted: Tue Jun 12, 2007 5:47 pm    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts How to force a select query to abend neo4u DB2 1 Mon Apr 23, 2018 1:36 pm
No new posts Query to compare 2 values of 1 column... Poha Eater DB2 13 Fri Mar 09, 2018 10:45 am
No new posts How to replace the below query? pkmurali DB2 12 Tue Feb 27, 2018 9:51 pm
No new posts Receommendations required for adding ... Alan Playford JCL & VSAM 4 Wed Feb 14, 2018 4:01 pm
No new posts Need Guidance regarding UPDATE query Poha Eater DB2 3 Mon Feb 12, 2018 11:35 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us