in Education by
In SQL Server, it's possible to insert into a table using a SELECT statement: INSERT INTO Table (col1, col2, col3) SELECT col1, col2, col3 FROM other_table WHERE sql = 'cool' Is it also possible to update via a SELECT? I have a temporary table containing the values, and would like to update another table using those values. Perhaps something like this: UPDATE Table SET col1, col2 SELECT col1, col2 FROM other_table WHERE sql = 'cool' WHERE Table.id = other_table.id Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
Use this code to UPDATE via SELECT in SQL Server: UPDATE Table X SET Table_X.col1 = Table_Y.col1, Table_X.col2 = Table_Y.col2, FROM One_Table AS Table_X INNER JOIN Another_Table as Table_Y ON TableX.id=TableY.id WHERE TableX.col3=’Cool’ Want to learn SQL from basics! Here's the right video for you on SQL provided by Intellipaat: OR UPDATE table1 SET Col1 = a.Col1, Col2 = a.Col2 FROM ( SELECT ID, Col1, Col2 FROM some_table) a WHERE a.ID= table1.ID Hope this helps you!

Related questions

0 votes
    How do I perform an IF...THEN in an SQL SELECT statement? For example: SELECT IF(Obsolete = 'N' OR ... Saleable, * FROM Product Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    I have a user defined function in SQL called getBuisnessDays it takes @startdate and @enddate and returns the number of ... WHERE ... Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I have a user defined function in SQL called getBuisnessDays it takes @startdate and @enddate and returns the number of ... WHERE ... Select the correct answer from above options...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    I need to remove a highly referenced table in a SQL Server database. How can I get a list of all the ... of the management studio.) Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    SELECT GETDATE() Returns: 2008-09-22 15:24:13.790 I want that date part without the time part: 2008-09-22 00: ... How can I get that? Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    I have seen SQL that uses both != and for not equal. What is the preferred syntax and why? I like !=, ... reminds me of Visual Basic. Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    I have multiple set of data to insert at once, say 4 rows. My table has three columns: Person, Id and ... a single SQL statement? Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    I have multiple set of data to insert at once, say 4 rows. My table has three columns: Person, Id and ... a single SQL statement? Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    How do I do a SELECT * INTO [temp table] FROM [stored procedure]? Not FROM [Table] and without defining [ ... not supply any columns. Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    Consider a database table holding names, with three rows: Peter Paul Mary Is there an easy way to turn this into ... Peter, Paul, Mary? Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    Could anybody tell me where I can learn Microsoft SQL Server? Select the correct answer from above options...
asked Jan 6, 2022 in Education by JackTerrance
0 votes
    I didn't see any similar questions asked on this topic, and I had to research this for something I'm working ... had the same question. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I didn't see any similar questions asked on this topic, and I had to research this for something I'm working ... had the same question. Select the correct answer from above options...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    I need to synchronize two tables. TableA Id Name TableB Id Name RefID --It's a Foreign key, defined as ... MATCHED BY TARGET THEN. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I need to synchronize two tables. TableA Id Name TableB Id Name RefID --It's a Foreign key, defined as ... MATCHED BY TARGET THEN. Select the correct answer from above options...
asked Feb 5, 2022 in Education by JackTerrance
...