简体   繁体   中英

Inserting data from another table - Oracle SQL

I need to insert data into a media table. The data must have the media id (which is a sequence), format (DVD, VHS) and the movie title id which is a sequence that exists another table named movies. How do I pull the data for the title_id from the movies table into the media table? I'm not quite sure where to start but I've listed the code I have so far for the first 2 columns.

INSERT INTO m_media
  (media_id, format, title_id)
VALUES (media_id_seq.NEXTVAL, 'DVD', );

Instead of inserting separate values, use SELECT statement which will fetch data from the movies table. Something like this:

insert into m_media (media_id, format, title_id)
  select media_id_seq.nextval, 
         'DVD',
         m.title_id
    from movies m
    where ...     --> condition, if you want to restrict rows returned by that SELECT

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM