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
 
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: 1777
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 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 Select numeric portion from CHAR data... balaji81_k DB2 6 Sat Aug 19, 2017 1:51 am
No new posts SQL - select data available in index Nileshkul DB2 3 Mon Jun 26, 2017 1:30 am

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