Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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 Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us