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 |
|
ssg14j
Starting Member
1 Post |
Posted - 2010-03-19 : 01:18:52
|
| I have 2 tables emp, emp1 with the fields id, name, age in both the tables.I need to delete the id which is common in both the tables emp,emp1.i tried the query "delete emp,emp1 from emp,emp1 where emp.id=emp1.id and emp.id='xx'"I got syntax error.I tried using join also to delete the data from 2 tables @ a time.Please help me to get the correct query..Thanx,S.S.G |
|
|
haroon2k9
Constraint Violating Yak Guru
328 Posts |
Posted - 2010-03-19 : 01:21:59
|
quote: Originally posted by ssg14j I have 2 tables emp, emp1 with the fields id, name, age in both the tables.I need to delete the id which is common in both the tables emp,emp1.i tried the query "delete emp,emp1 from emp,emp1 where emp.id=emp1.id and emp.id='xx'"I got syntax error.I tried using join also to delete the data from 2 tables @ a time.Please help me to get the correct query..Thanx,S.S.G
delete from(select emp.*,emp1.* from emp inner join emp2 on emp.id=emp1.id)as t |
 |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-03-19 : 01:25:02
|
quote: Originally posted by haroon2k9
quote: Originally posted by ssg14j I have 2 tables emp, emp1 with the fields id, name, age in both the tables.I need to delete the id which is common in both the tables emp,emp1.i tried the query "delete emp,emp1 from emp,emp1 where emp.id=emp1.id and emp.id='xx'"I got syntax error.I tried using join also to delete the data from 2 tables @ a time.Please help me to get the correct query..Thanx,S.S.G
delete from(select emp.*,emp1.* from emp inner join emp2 on emp.id=emp1.id)as t
Just Correcting a type Odelete from(select emp.*,emp2.* from emp inner join emp1 on emp.id=emp1.id)as tSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-03-19 : 01:59:42
|
quote: Originally posted by ssg14j I have 2 tables emp, emp1 with the fields id, name, age in both the tables.I need to delete the id which is common in both the tables emp,emp1.i tried the query "delete emp,emp1 from emp,emp1 where emp.id=emp1.id and emp.id='xx'"I got syntax error.I tried using join also to delete the data from 2 tables @ a time.Please help me to get the correct query..Thanx,S.S.G
Do you want to delete data from both the tables?MadhivananFailing to plan is Planning to fail |
 |
|
|
haroon2k9
Constraint Violating Yak Guru
328 Posts |
Posted - 2010-03-19 : 02:04:09
|
quote: Originally posted by madhivanan
quote: Originally posted by ssg14j I have 2 tables emp, emp1 with the fields id, name, age in both the tables.I need to delete the id which is common in both the tables emp,emp1.i tried the query "delete emp,emp1 from emp,emp1 where emp.id=emp1.id and emp.id='xx'"I got syntax error.I tried using join also to delete the data from 2 tables @ a time.Please help me to get the correct query..Thanx,S.S.G
Do you want to delete data from both the tables?MadhivananFailing to plan is Planning to fail
please see the hightlighted in red color,what OP tried to do ..please correct me if iam wrong(Kind Request)madhi. |
 |
|
|
haroon2k9
Constraint Violating Yak Guru
328 Posts |
Posted - 2010-03-19 : 02:05:25
|
quote: Originally posted by senthil_nagore
quote: Originally posted by haroon2k9
quote: Originally posted by ssg14j I have 2 tables emp, emp1 with the fields id, name, age in both the tables.I need to delete the id which is common in both the tables emp,emp1.i tried the query "delete emp,emp1 from emp,emp1 where emp.id=emp1.id and emp.id='xx'"I got syntax error.I tried using join also to delete the data from 2 tables @ a time.Please help me to get the correct query..Thanx,S.S.G
delete from(select emp.*,emp1.* from emp inner join emp2 on emp.id=emp1.id)as t
Just Correcting a type Odelete from(select emp.*,emp2.* from emp inner join emp1 on emp.id=emp1.id)as tSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/
oops!.thanks. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-03-19 : 02:48:09
|
quote: Originally posted by haroon2k9
quote: Originally posted by madhivanan
quote: Originally posted by ssg14j I have 2 tables emp, emp1 with the fields id, name, age in both the tables.I need to delete the id which is common in both the tables emp,emp1.i tried the query "delete emp,emp1 from emp,emp1 where emp.id=emp1.id and emp.id='xx'"I got syntax error.I tried using join also to delete the data from 2 tables @ a time.Please help me to get the correct query..Thanx,S.S.G
Do you want to delete data from both the tables?MadhivananFailing to plan is Planning to fail
please see the hightlighted in red color,what OP tried to do ..please correct me if iam wrong(Kind Request)madhi.
Ok. It should bedeclare @t table(id int)insert into @tselect e.id from emp as e inner join emp1 as e1 on e.id=e1.iddelete from emp where id in (select id from @t)delete from emp1 where id in (select id from @t)MadhivananFailing to plan is Planning to fail |
 |
|
|
haroon2k9
Constraint Violating Yak Guru
328 Posts |
Posted - 2010-03-19 : 02:53:03
|
quote: Originally posted by madhivanan
quote: Originally posted by haroon2k9
quote: Originally posted by madhivanan
quote: Originally posted by ssg14j I have 2 tables emp, emp1 with the fields id, name, age in both the tables.I need to delete the id which is common in both the tables emp,emp1.i tried the query "delete emp,emp1 from emp,emp1 where emp.id=emp1.id and emp.id='xx'"I got syntax error.I tried using join also to delete the data from 2 tables @ a time.Please help me to get the correct query..Thanx,S.S.G
Do you want to delete data from both the tables?MadhivananFailing to plan is Planning to fail
please see the hightlighted in red color,what OP tried to do ..please correct me if iam wrong(Kind Request)madhi.
Ok. It should bedeclare @t table(id int)insert into @tselect e.id from emp as e inner join emp1 as e1 on e.id=e1.iddelete from emp where id in (select id from @t)delete from emp1 where id in (select id from @t)MadhivananFailing to plan is Planning to fail
Hi madhi,what about this..doesn't this do it?Hope you have valid reason not use of this..or you have shown other method of doing it?.could you please explain ?delete from(select emp.*,emp1.* from emp inner join emp1 on emp.id=emp1.id)as t |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-03-19 : 02:57:33
|
quote: Originally posted by haroon2k9
quote: Originally posted by madhivanan
quote: Originally posted by haroon2k9
quote: Originally posted by madhivanan
quote: Originally posted by ssg14j I have 2 tables emp, emp1 with the fields id, name, age in both the tables.I need to delete the id which is common in both the tables emp,emp1.i tried the query "delete emp,emp1 from emp,emp1 where emp.id=emp1.id and emp.id='xx'"I got syntax error.I tried using join also to delete the data from 2 tables @ a time.Please help me to get the correct query..Thanx,S.S.G
Do you want to delete data from both the tables?MadhivananFailing to plan is Planning to fail
please see the hightlighted in red color,what OP tried to do ..please correct me if iam wrong(Kind Request)madhi.
Ok. It should bedeclare @t table(id int)insert into @tselect e.id from emp as e inner join emp1 as e1 on e.id=e1.iddelete from emp where id in (select id from @t)delete from emp1 where id in (select id from @t)MadhivananFailing to plan is Planning to fail
Hi madhi,what about this..doesn't this do it?Hope you have valid reason not use of this..or you have shown other method of doing it?.could you please explain ?delete from(select emp.*,emp1.* from emp inner join emp1 on emp.id=emp1.id)as t
That will not workYou can't delete a derived table which is derived from more than one tableMadhivananFailing to plan is Planning to fail |
 |
|
|
haroon2k9
Constraint Violating Yak Guru
328 Posts |
Posted - 2010-03-19 : 03:09:32
|
quote: That will not workYou can't delete a derived table which is derived from more than one table
Thanks.Good explanation.I understood. |
 |
|
|
|
|
|
|
|