Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
rjhe22
Constraint Violating Yak Guru
283 Posts |
Posted - 2012-09-06 : 07:07:13
|
| hii want to delete stuff from a table based on a columnso egid first last1 john joe2 paul smith1 ronan waldron so what i want is to say delete the 1 from the table without have to putis like thisdelete from tbale 1where id ='1'any ideas |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-09-06 : 07:32:23
|
in this example: delete ALL rows with id=1? Too old to Rock'n'Roll too young to die. |
 |
|
|
rjhe22
Constraint Violating Yak Guru
283 Posts |
Posted - 2012-09-06 : 07:45:50
|
| ya all rows that are 1 but with out actually putting the number into the query |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-09-06 : 07:57:18
|
Try this:delete t1from YourTable as t1join (select id from YourTable group by id having count(*) > 1)t2on t1.id = t2.id Too old to Rock'n'Roll too young to die. |
 |
|
|
rjhe22
Constraint Violating Yak Guru
283 Posts |
Posted - 2012-09-06 : 09:26:25
|
| hi ya thats looks goodbut say i want to do it where its not a number its a name will the code still work then |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-09-06 : 09:31:49
|
Yes. Just replace each occurence of "id" with the needed column name and be sure to have a test... Too old to Rock'n'Roll too young to die. |
 |
|
|
xploddbash
Starting Member
2 Posts |
Posted - 2012-09-06 : 19:40:09
|
| Just base it to the name when they have the same "id". The column would be deleted with that. |
 |
|
|
rjhe22
Constraint Violating Yak Guru
283 Posts |
Posted - 2012-09-13 : 05:35:33
|
| hisorry just getting back to this nowthat delete still deletes all the data from table |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-09-13 : 10:23:49
|
| what do you mean by all data?are you looking at specifically removing data from a column in a row having a value or is your attempt to remove entire row having the required data?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|