SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


DELETE using INNER JOIN


DELETE using INNER JOIN

Author
Message
FootyRef
FootyRef
SSC-Addicted
SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)

Group: General Forum Members
Points: 431 Visits: 79
I was not the one who originally asked the question. I just searched and found this answer to a problem I was having here deleting records using a JOIN. I am using the SQLTerm tool within Cognos Data Manager and that was how the SQL was formed when the tool did it, so I just cut and pasted it into this thread to show the solution to my issue.
inception
inception
SSC Rookie
SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)

Group: General Forum Members
Points: 45 Visits: 2
Hello,

I'm quite new to SQL. Is there any way someone could re-write the statement posted above, to generic terms? i.e., with Table 1, Table 2, Column 1, etc.

DELETE a
FROM "dbo"."DM_ConformedPerson" a
JOIN "dbo"."TST_Fix_DM_ConformedPerson" z
ON a."Person_SK" = z."Person_SK"
WHERE z."Person_SK" <> z."MaxSK"

thanks all!
Vikash Anil
Vikash Anil
SSC Rookie
SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)

Group: General Forum Members
Points: 32 Visits: 14
Use following




DELETE ord
FROM Orders ord
INNER JOIN Customers c(nolock)
ON ord.CustomerID = c.CustomerID
WHERE c.FirstName = 'vikash'


regards,

blog.learnonlinewithme.com
das_bhasker
das_bhasker
SSC Rookie
SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)

Group: General Forum Members
Points: 47 Visits: 11
Thanks Rajat, Your solutions saved my hours.

Thanks again Smile
sagscorp22
sagscorp22
SSC Rookie
SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)

Group: General Forum Members
Points: 41 Visits: 3
I know. It's old post still thanks.
I was doing delete from too.
Your reply helped.
brahmaji_85 79292
brahmaji_85 79292
SSC Rookie
SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)

Group: General Forum Members
Points: 26 Visits: 9
Thanks a lot.........:-)
turkey-500673
turkey-500673
SSC Veteran
SSC Veteran (296 reputation)SSC Veteran (296 reputation)SSC Veteran (296 reputation)SSC Veteran (296 reputation)SSC Veteran (296 reputation)SSC Veteran (296 reputation)SSC Veteran (296 reputation)SSC Veteran (296 reputation)

Group: General Forum Members
Points: 296 Visits: 57
Thanks for this. I was going nuts with syntax error until I saw your script that used th alias instead of the table name. Simple but brilliant!
thanks again.:-)
kapilraut02
kapilraut02
Valued Member
Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)

Group: General Forum Members
Points: 55 Visits: 2
SELECT * into #tempDocFragToDelete FROM
DocumentFragmentRelationShipHistory WHERE DocumentFragmentMasterId =391
AND DocumentFragmentVersionID=1.0


DELETE a from DocumentFragmentRelationShipHistory a join #tempDocFragToDelete b
on a.DocumentFragmentMasterId = b.DocumentFragmentMasterId
where a.DocumentFragmentVersionID > b.DocumentFragmentVersionID


This one is a real running example, try this.
forsqlserver
forsqlserver
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10808 Visits: 2078
Hi vikash,

In my case I want to delete those data which is not selecting in below join any Help..


DELETE ord FROM Orders ord INNER JOIN Customers c(nolock) ON ord.CustomerID = c.CustomerID WHERE c.FirstName = 'vikash'

Thanks
Kingston Dhasian
Kingston Dhasian
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11353 Visits: 5331
forsqlserver (7/23/2012)
Hi vikash,

In my case I want to delete those data which is not selecting in below join any Help..


DELETE ord FROM Orders ord INNER JOIN Customers c(nolock) ON ord.CustomerID = c.CustomerID WHERE c.FirstName = 'vikash'


Please create a separate thread for your problem
Also note that this is an old thread and the person you are referring to might not be online always to help you out

If you create a new thread with some sample data and DDL of the tables invloved, I am sure there are many here who can help out in no time
If you don't know how to do this, go through the link in my signature


Kingston Dhasian

How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search