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

Select query in teradata


IBM Mainframe Forums -> All Other Mainframe Topics
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
prasanthiv

New User


Joined: 07 Dec 2008
Posts: 6
Location: INDIA

PostPosted: Wed Feb 24, 2010 8:43 pm
Reply with quote

Hi,

I have a data like shown below and is coming from my select query in teradata.

Code:
COLA | COLB| COLC| COLD
11   | 22  | AB  |  BC
11   | 23  | CD  |  DE

From above data i need to insert into another table any of one row in i.e either
11 | 22 | AB | BC (or) 11 | 23 | CD | DE

but not both..I can't use distinct becaz data is duplicated in only first column. Any Idea?
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: Wed Feb 24, 2010 10:26 pm
Reply with quote

Hello,

Neither "what you have" nor "what you want is clear from your post.

Why is distinct mentioned?

Suggest you provide a more detailed explanation of the requirement.

Keep in mind that your question is completely clear to you, but may not be to others, so more clarification is needed.
Back to top
View user's profile Send private message
prasanthiv

New User


Joined: 07 Dec 2008
Posts: 6
Location: INDIA

PostPosted: Wed Feb 24, 2010 10:56 pm
Reply with quote

Data in table A

COLID | COLB| COLC| COLD
11 | 22 | AB | BC
11 | 23 | CD | DE


Table B

same structure as table A




As shown above

We can see more than one row in table A for COLID "11".


When am inserting data in to table B from table A, I need one entry of COLID "11" inserted into table B


So after inserting data in table B, data in table B should Be either

TABLE B
COLID | COLB| COLC| COLD
11 | 22 | AB | BC

or

TABLE B
COLID | COLB| COLC| COLD
11 | 23 | CD | DE


Hope am clear this time..Sorry if am not clear still..
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Thu Feb 25, 2010 12:19 am
Reply with quote

So you're looking for something like
Code:
INSERT INTO B             
(SELECT * FROM A           
 WHERE COLID = some-value
 FETCH FIRST 1 ROW ONLY)   
Back to top
View user's profile Send private message
prasanthiv

New User


Joined: 07 Dec 2008
Posts: 6
Location: INDIA

PostPosted: Thu Feb 25, 2010 12:23 am
Reply with quote

Yes..am looking some thing similar but fetch first row only won't work in teradata sql.. It works in DB2

Thanks,
Prasanthi.
Back to top
View user's profile Send private message
prasanthiv

New User


Joined: 07 Dec 2008
Posts: 6
Location: INDIA

PostPosted: Thu Feb 25, 2010 12:43 am
Reply with quote

HI All,

I tried something like this and it is working. Since i can select any of one entry for COLID 11

Insert into table B
Select COLID
,max(COLB)
,max(COLC)
,max(COLD)
from table A
Group by 1;

If anybody has better solution please let me know..Thank you all for your time...

Prasanthi
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 -> All Other Mainframe Topics

 


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 SELECT from data change table DB2 5
Search our Forums:

Back to Top