0

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

2
  • Hi, are they on same machine? and what is yor dbms? Commented Feb 3, 2021 at 18:48
  • @MohammadMirsafaei They're on Amazon Aurora, compatible with MySQL and PostgreSQL Commented Feb 3, 2021 at 19:00

1 Answer 1

1

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]
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.