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 HEX value search in a DB2 query maxsubrat DB2 2 Wed Oct 04, 2017 3:04 pm
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm

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