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 > DATE/ALIAS issue

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-10-11, 05:02
brucezepplin brucezepplin is offline
Registered User
 
Join Date: Jul 2011
Posts: 19
DATE/ALIAS issue

Hi everyone, I am having a problem including aliased dates in as part of the criteria for a JOIN clause. I have:

Code:
SELECT * FROM

(SELECT DISTINCT PERSON,  DATE AS DATE1
FROM DB1
) A

INNER JOIN

(SELECT DISTINCT PERSON, DATE AS DATE2
FROM DB2
) B

ON A.PERSON = B.PERSON
AND DATE1 BETWEEN (DATE2 - 1 YEAR) AND DATE2
and it's the last line that's giving me the problem. I am being told that DATE1 and DATE2 are both invalid in the context they are used. Any know how to solve this? accessing them as A.DATE gives me the same problem also. So it doesn't sound like an alias issue.

Thanks!
Reply With Quote
  #2 (permalink)  
Old 08-10-11, 05:06
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
what is the data type for DATE column in DB1 and DB2 tables ?
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old 08-10-11, 06:09
brucezepplin brucezepplin is offline
Registered User
 
Join Date: Jul 2011
Posts: 19
reply

they are both of type DATE.
Reply With Quote
  #4 (permalink)  
Old 08-10-11, 06:46
brucezepplin brucezepplin is offline
Registered User
 
Join Date: Jul 2011
Posts: 19
Solved

I needed to put the Person in a GROUP BY clause within their own sub-select clause. Problem solved.
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