Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Delete Query Expand / Collapse
Author
Message
Posted Wednesday, September 15, 2010 2:31 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, October 9, 2014 10:43 AM
Points: 39, Visits: 192
Hi friends need Delete Query

Delete from StoreGroupMember Where d in (select * from StoreGroupMember a ,store where a.Store_id=Store.id and store.StoreNumber=9833) d
Go

I need to Delete the Records which Satisfies the Below condition,

select * from Table1 a ,Table2 where a.Store_id=Tables2.id and Table2.StoreNumber='AAAA'

And i need to delete the records from Table 1 only,

EG;

Delete from Table1 Where d in (select * from Table1 a ,Table2 where a.Store_id=Tables2.id and Table2.StoreNumber='AAAA') d
Go

Please help me out...

URGENT


Post #986689
Posted Wednesday, September 15, 2010 2:36 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Tuesday, November 25, 2014 9:51 AM
Points: 5,446, Visits: 7,616
The more urgently you need something, the more time you'll need to take writing out the sample code you'd like us to mess with. A couple of things though:

That select * statement? It won't help us figure out what the key/keys are in Table1 to uniquely identify each delete.

General syntax though to delete:
DELETE t1
FROM
Table1 AS t1
JOIN
Table2 AS t2
ON t1.id = t2.id
WHERE
t2.colB = @parameter




- Craig Farrell

Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

For better assistance in answering your questions | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
Post #986694
Posted Wednesday, September 15, 2010 2:38 PM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Wednesday, April 30, 2014 12:57 PM
Points: 575, Visits: 692
This should work, I think..:

DELETE D FROM Table1 AS D
INNER JOIN StoreGroupMember A
ON A.Store_ID = D.Store_ID
WHERE A.StoreNumber = 9833

I think I got the tables right, but it's a bit unclear. Are the StoreNumber and Store_ID fields both in the StoreGroupMember table? And you want to delete by StoreNumber?
Post #986697
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse