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
 

 

Select query in teradata

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics
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    Post subject: Select query in teradata
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

Site Director


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

PostPosted: Wed Feb 24, 2010 10:26 pm    Post subject:
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    Post subject: Reply to: help on query
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: 1771
Location: Bloomington, IL

PostPosted: Thu Feb 25, 2010 12:19 am    Post subject:
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    Post subject: Reply to: help on query
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    Post subject: Reply to: help on query
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    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts SQL - select data available in index Nileshkul DB2 3 Mon Jun 26, 2017 1:30 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
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Omegamon for DB2 query ashek15 DB2 0 Wed Feb 15, 2017 11:25 am


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