Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

mysql insere o resultado da consulta de várias linhas na tabela

INSERT INTO `documentcounters`
(`DataChar`,`SeqNum`,`LastSignature`,`DocumentType`,`SalesTerminal`,`Active`)
SELECT Q1.in_headers, -1,NULL, 17,0,0 FROM 
    (SELECT DISTINCT(DocumentSeries) as in_headers  FROM transactionsheaders )AS Q1
    LEFT JOIN 
    (SELECT DISTINCT(DataChar) as in_counters FROM documentcounters)AS Q2
ON Q1.in_headers=Q2.in_counters WHERE Q2.in_counters IS NULL;

Isso funcionará se UID é definido como auto_increment .