shivanand sb shivanand sb - 2 months ago 6
SQL Question

How to Update Executed table result into the same table?

I have created a table

tbl_Dist
with Column names
District
and
DistCode
, there were many duplicate values in the District table so i have removed all the duplicates value using this statement:

select distinct District from tbl_Dist;


its done, but i am not getting how to update the results of the above executed querry to the table
tbl_Dist
?

Answer

You can as the below:

-- Move temp table
SELECT DISTINCT District INTO TmpTable FROM tbl_Dist
-- Delete all data
DELETE FROM tbl_Dist
-- Insert data from temp table
INSERT INTO tbl_Dist
SELECT * FROM TmpTable
Comments