Reputation: 49
I have two different databases. The first, let's call it db_client, contains a table called played_songs. In played_songs, there is a column called song_name.
I have a second database called db_system, which has a table called songs. In the songs table, there is also a column called song_name.
How can I select and update rows in db_system's songs table which have the same song_name as the rows in db_client's played_songs? There is also another column in db_system's songs table which is called image, which I want to set NULL if the song_name from db_system's songs table is in db_client's played_songs table
Upvotes: 0
Views: 75
Reputation: 36
You can select columns from different tables BUT the Databases must be in the same server.
SELECT t1.[Column Name]
,t1.[Column Name]
,t2.[Column Name]
,t2.[Column Name]
FROM [DB1].[table1] t1
join [DB2].[table2] t2
on t1.ID = t2.ID
With the INSERT or UPDATE you have to refer in which database exist the table.
Update [DB1].[table1]
SET column1 = value1,
column2 = value2,
WHERE [condition]
Upvotes: 1