Search code examples
sqloracle-databasepsql

How to Join Two Tables an Update Only on SELECT Statement Without Applying any Update into Tables in Oracle


I have two tables in Oracle database called tbl_genres and tbl_movies theirs basic schema looks like this

tbl_genres

enter image description here

tbl_movies

enter image description here

Now what I need to have is updating the output only on SELECT statement without applying update into tbl_movies and getting a result like this

enter image description here


Solution

  • This can be accomplished using an INNER JOIN:

    select t1.movie as Movie, t2.genre_name as Genre from tbl_movies as t1
    inner join tbl_genres as t2 on t1.m_genre=t2.genreid;
    

    This works by selecting the movie and genre columns, and joining them together on the basis of a common identifier (in this case, m_genre/genre_id).