| Author |
Topic |
|
shijiltvsql
Starting Member
4 Posts |
Posted - 2009-01-15 : 08:24:23
|
| hai iam new to forumsgive instructions and tips to utilise this site properlyi have a table as likesno sname age1 aaa 182 bbb 193 aaa 18i want to delete only first row by using conditionstv |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-15 : 08:27:33
|
| [code]delete t from(select row_number() over (partition by sname order by sno desc) as seqfrom table)twhere seq >1[/code] |
 |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-01-15 : 10:51:41
|
quote: Originally posted by visakh16
delete t from(select row_number() over (partition by sname order by sno desc) as seq,* from table)twhere seq >1
|
 |
|
|
shijiltvsql
Starting Member
4 Posts |
Posted - 2009-01-23 : 10:27:30
|
| while checking the query i got an error'row_number' is not a recognized function name.and what is seqcan u help mestv |
 |
|
|
cat_jesus
Aged Yak Warrior
547 Posts |
Posted - 2009-01-23 : 10:36:30
|
| Are you using SQL Server 2005?If so is the database in 2000 compatability mode?An infinite universe is the ultimate cartesian product. |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2009-01-23 : 11:03:14
|
quote: Originally posted by shijiltvsql while checking the query i got an error'row_number' is not a recognized function name.and what is seqcan u help mestv
try thisdelete rfrom table rLEFT JOIN ( SELECT MAX(sno) rowno ,sname,age FROM TABLE GROUP BY sname,age ) t ON t.rowno = r.snoWHERE t.rowno IS NULL |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-23 : 11:10:18
|
quote: Originally posted by sodeep
quote: Originally posted by visakh16
delete t from(select row_number() over (partition by sname order by sno desc) as seq,* from table)twhere seq >1
no need of * as i'm deleting why simply include all columns? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-23 : 11:11:53
|
quote: Originally posted by raky
quote: Originally posted by shijiltvsql while checking the query i got an error'row_number' is not a recognized function name.and what is seqcan u help mestv
try thisdelete rfrom table rLEFT JOIN ( SELECT MAX(sno) rowno ,sname,age FROM TABLE GROUP BY sname,age ) t ON t.rowno = r.snoWHERE t.rowno IS NULL
that deletes all except last rowit should be :-delete rfrom table rINNER JOIN ( SELECT MIN(sno) rowno ,sname,age FROM TABLE GROUP BY sname,age ) t ON t.rowno = r.sno |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-23 : 11:13:01
|
quote: Originally posted by shijiltvsql while checking the query i got an error'row_number' is not a recognized function name.and what is seqcan u help mestv
what does this return?SELECT @@VERSIONEXEC sp_dbcmptlevel yourdb |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2009-01-23 : 11:16:24
|
quote: Originally posted by visakh16
quote: Originally posted by raky
quote: Originally posted by shijiltvsql while checking the query i got an error'row_number' is not a recognized function name.and what is seqcan u help mestv
try thisdelete rfrom table rLEFT JOIN ( SELECT MAX(sno) rowno ,sname,age FROM TABLE GROUP BY sname,age ) t ON t.rowno = r.snoWHERE t.rowno IS NULL
that deletes all except last rowit should be :-delete rfrom table rINNER JOIN ( SELECT MIN(sno) rowno ,sname,age FROM TABLE GROUP BY sname,age ) t ON t.rowno = r.sno
yaa if op have more than two records with same combination of sname,age.My query will delete all rows except the maxid combination. |
 |
|
|
|