13,044,927 members (43,207 online)
Rate this:
See more:
Hi,
I have a table with five rows. i want to update the last four rows with the values of first record. First row contain the master record. How can i do that. plz help me

kunjammu
Posted 8-Jan-13 21:57pm
Kunjammu1.2K
Updated 8-Jan-13 22:01pm
v2
pranathis012 9-Jan-13 3:59am

Kunjammu 9-Jan-13 4:01am

made some changes in my question
pranathis012 9-Jan-13 4:08am

IN UR TABLE ANY PK COL IS THERE
Kunjammu 9-Jan-13 4:09am

yes. RECNO is my Pk
Milind_T 9-Jan-13 4:08am

Do you have primary key set on the table ?
Kunjammu 9-Jan-13 4:10am

yes. RECNO is my Pk
Milind_T 9-Jan-13 4:15am

Good, check the solution below. That should help.

Rate this:

## Solution 1

Sorry, I misread the question. You can do this:

update table1 set val = ( select top 1 val from table1 order by id)

You'd have to do that for each column. You can do it all in one, if you like.

update table1 set val = ( select top 1 val from table1 order by id),
val2 = (select top 1 val2 from table1 order by id), etc
v2
Kunjammu 9-Jan-13 4:09am

can u plz give me an example
Christian Graus 9-Jan-13 4:12am

Oh, I see. Update table set val = (select top 1 val from table) will do it. I misread your question. Make sure top 1 is selecting the first record, perhaps order by the id to do that ?
Rate this:

## Solution 2

```
UPDATE TABLE_NAME SET
COL_NAME=(SELECT COL_NAME FROM TABLE_NAME WHERE RECNO= 1)
```
v3
Rate this:

## Solution 3

Check following query

```UPDATE myTable
SET
column1 = firstrow.column1,
column1 = firstrow.column1,
column1 = firstrow.column1
FROM
(
SELECT
column1,column2,column3
FROM MyTable
WHERE
RECNO=1
) firstrow
where RECNO<> 1```

That should serve the purpose

Hope that helps
Milind
v2
Kunjammu 9-Jan-13 4:44am

thank u...

Top Experts
Last 24hrsThis month
 OriginalGriff 278 ppolymorphe 139 Graeme_Grant 70 F-ES Sitecore 70 kp564 70
 OriginalGriff 4,563 RickZeeland 1,844 ppolymorphe 1,698 F-ES Sitecore 1,553 Dave Kreskowiak 1,349