简体   繁体   中英

Get columns from one table to another

So I'll create a combination of all first names and all surnames from a table (Person).

insert into tabell_med_navn 
select f.fornavn, e.etternavn
from person f cross join person e

These combinations should then be added to a table I have made earlier.

create table tabell_med_navn (
  id int not null auto_increment,
  fornavn varchar(40) null,
  etternavn varchar(40) null,
  primary key (id)
);

It is when I am trying to send the combination over it fails. Anybody know why it fails?

List the columns being inserted:

insert into tabell_med_navn (fornavn, etternavn)
    select f.fornavn, e.etternavn
    from person f cross join
         person e;

This will assign a default value to the id column.

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