Delete using Inner join
This article will explain how to
delete values based on another table.
Create Student table
CREATE TABLE #Student (NAME VARCHAR(10), Age INT, Result varchar(10))
Insert some data in student table
INSERT INTO #Student
(NAME, Age, Result)
SELECT 'Raj', 21,''
SELECT 'Maaz', 22, ''
SELECT 'Mack', 21, ''
SELECT 'Razz', 24, ''
SELECT 'Laz', 25, ''
SELECT 'Daz', 22, ''
Create Marks Table
CREATE TABLE #Marks(NAME VARCHAR(10),Total int)
Insert some data in Marks table
INSERT INTO #Marks
SELECT 'Maaz', 44
SELECT 'Mack', 33
SELECT 'Razz', 67
SELECT 'Laz', 87
SELECT 'Daz', 99
Select data from both table to view what is
SELECT * FROM #Student
SELECT * FROM #Marks
Delete with inner join
Here we are going to set delete
student based on their marks. If marks are less than 50 then student is will be
DELETE #Student FROM #Student INNER JOIN #Marks ON #Student.NAME = #Marks.NAME WHERE #Marks.Total < 50
Select data from both table to view result.
SELECT * FROM #StudentSELECT * FROM #Marks
No response found. Be the first to respond this post
You must Sign In To post reply
|Find More code samples in C#, ASP.Net, Vb.Net and more Here|