Search
 
SCRIPT & CODE EXAMPLE
 

SQL

sql update from select

UPDATE YourTable 
SET Col1 = OtherTable.Col1, 
    Col2 = OtherTable.Col2 
FROM (
    SELECT ID, Col1, Col2 
    FROM other_table) AS OtherTable
WHERE 
    OtherTable.ID = YourTable.ID
Comment

Update Query in SQL Server

 
  UPDATE table1
  SET column2 = 'Your Text', column3 = 45000
  WHERE column1=5

Comment

How do I UPDATE from a SELECT in SQL Server?


In SQL Server 2008 (or newer), use MERGE

MERGE INTO YourTable T
   USING other_table S 
      ON T.id = S.id
         AND S.tsql = 'cool'
WHEN MATCHED THEN
   UPDATE 
      SET col1 = S.col1, 
          col2 = S.col2;
Alternatively:

MERGE INTO YourTable T
   USING (
          SELECT id, col1, col2 
            FROM other_table 
           WHERE tsql = 'cool'
         ) S
      ON T.id = S.id
WHEN MATCHED THEN
   UPDATE 
      SET col1 = S.col1, 
          col2 = S.col2;
Comment

Update Query in SQL Server


  Update salesTransaction
  Set Unit_Price=45.41,Item_Number='Milk-1'
  Where trx_id=1249
Comment

How do I UPDATE from a SELECT in SQL Server?

UPDATE     Table_A SET     Table_A.col1 = Table_B.col1,     Table_A.col2 = Table_B.col2 FROM     Some_Table AS Table_A     INNER JOIN Other_Table AS Table_B         ON Table_A.id = Table_B.id WHERE     Table_A.col3 = 'cool'
Comment

update select sql

--the simplest way of doing this 
UPDATE
    table_to_update,
    table_info
SET
    table_to_update.col1 = table_info.col1,
    table_to_update.col2 = table_info.col2

WHERE
    table_to_update.ID = table_info.ID
Comment

PREVIOUS NEXT
Code Example
Sql :: connect by query in oracle 
Sql :: plpgsql coalesce equivalent for empty string 
Sql :: oracle ora-00054 how to unlock 
Sql :: mysql sublime build system 
Sql :: trigger sql 
Sql :: download database devilbox 
Sql :: mysql custom sort order 
Sql :: time in sql server 
Sql :: mssql replace first occurrence 
Sql :: insert data into multiple tables mysql 
Sql :: date datatype in livesql 
Sql :: get comma separated values in mysql with group by 
Sql :: alter in sql 
Sql :: datetrunc month sql 
Sql :: getting customers with no orders sql 
Sql :: mysql dependency for spring boot 
Sql :: sqlite higher or equal 
Sql :: sql alternative to max statement 
Sql :: row number sql 
Sql :: mysql dump structure only 
Sql :: what is subquery in sql 
Sql :: sql query print strings and int 
Sql :: Oracle cx_Oracle example 
Sql :: change date in pivot table to month in sql server 
Sql :: mamp mysql password 
Sql :: sql recherche nom prenom 
Sql :: inspecting a column unique/distinct values in SQL 
Sql :: sql join 3 tables 
Sql :: postgres ERROR: relation "user" does not exist 
Sql :: Should I use the datetime or timestamp data type in MySQL? 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =