Copy one column to another sqlserver

UPDATE table SET columnB = columnA

–This will update every row.

UPDATE table_name SET
destination_column_name=orig_column_name
WHERE condition_if_necessary

–This will update rows which satisfy the WHERE clause

UPDATE table1
SET column1 = (
SELECT column2
FROM table2
WHERE table2.id = table1.id
);
Whereby:

table1 = table that has the column that needs to be updated
table2 = table that has the column with the data
column1 = blank column that needs the data from column2 (this is in table1)
column2 = column that has the data (that is in table2)

 

–This will update one column based on value of another table column

 

 

 

Advertisements

Inner Join in SQL Server

Tables are

a userbasic

b userlmits

c groupauthclass

— 2 Table Inner Join SQL Server —


select a.userid,a.groupid,a.username,a.branch, b.onlinedebit,b.offlinedebit
from dbo.userbasic a join dbo.userlimits b on a.userid=b.userid ;

— 3 Table Inner Join SQL Server —


select a.userid,a.groupid,c.classid,c.authority, b.onlinedebit,b.offlinedebit
from dbo.userbasic a join dbo.userlimits b on a.userid=b.userid
join dbo.groupauthclass c on c.groupid=a.groupid;