Ho una tabella con una chiave primaria di incremento automatico:MySQL inserire nella tabella con incremento automatico, mentre la selezione di un'altra tabella
create table rt_table
(
rtID int PRIMARY KEY AUTO_INCREMENT,
rt_user_id BIGINT, /*user being retweeted*/
rt_user_name varchar(70), /*user name of rt_user_id*/
source_user_id BIGINT, /*user tweeting rt_user_id*/
source_user_name varchar(70), /*user name of source_user_id*/
tweet_id BIGINT, /*fk to table tweets*/
FOREIGN KEY (tweet_id) references tweets(tweet_id)
);
desidero popolare questa tabella da parte di un altro tavolo:
insert into rt_table
select rt_user_id, (select user_name from users u where u.user_id = t.rt_user_id),
source_user_id, (select user_name from users u where u.user_id = t.source_user_id),
tweet_id
from tweets t
where rt_user_id != -1;
Viene visualizzato un errore che indica che il numero di colonne non corrisponde, a causa della chiave primaria (che è un valore autoincrementato e quindi non deve essere impostato). Come faccio a evitare questo?