View previous topic :: View next topic
|
Author |
Message |
prasanthiv
New User
Joined: 07 Dec 2008 Posts: 6 Location: INDIA
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
prasanthiv
New User
Joined: 07 Dec 2008 Posts: 6 Location: INDIA
|
|
|
|
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 |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
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 |
|
|
prasanthiv
New User
Joined: 07 Dec 2008 Posts: 6 Location: INDIA
|
|
|
|
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 |
|
|
prasanthiv
New User
Joined: 07 Dec 2008 Posts: 6 Location: INDIA
|
|
|
|
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 |
|
|
|