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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 dml help

Author  Topic 

wormz666
Posting Yak Master

110 Posts

Posted - 2008-10-23 : 04:09:42
how can i delete a record with in the 2 table

please help... i have no idea how to delete the 2 records having the
the same id................

and also insert data with 2 table having the same id.......

thank you in advance....

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-23 : 04:35:53
can you illustrate what you want with some data. cant make out what you're asking for? do you mean delete records from 2 tables or delete record with id 2 and then insert it to another table?
Go to Top of Page

wormz666
Posting Yak Master

110 Posts

Posted - 2008-10-23 : 05:57:53
what i mean delete from two table which has the same id then insert it into my back up 2 table

table1
id name
1 jason
2 Chris
3 Christian
table2
id occupation
1 accountant
2 engineer
3 government employee

i want to delete whos id is 1 then save it into my back up table

bactable1,bactable2.....
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-23 : 06:43:42
[code]INSERT INTO Backup
SELECT id,name
FROM
(
SELECT id,name,1 AS cat FROM table1
UNION ALL
SELECT id,name,2 AS cat FROM table2
)t
GROUP BY id,name
HAVING COUNT(cat) >1


DELETE t1 FROM table1 t1 INNER JOIN table2 t2 ON t1.id=t2.id
DELETE t2 FROM table1 t1 INNER JOIN table2 t2 ON t1.id=t2.id[/code]
Go to Top of Page
   

- Advertisement -