I have this query in mysql database:
INSERT INTO `table1`( `text1`, `text2`, `link` )
SELECT 
    `text1`,
    `text2``,
    `link`
FROM `table2`
WHERE `table1`.`code` = `table2`.`code`;
I get an error:
#1054 - Unknown column 'table1.code' in 'where clause'
What am I doing wrong? I have no aliases, I tried HAVING instead of WHERE, I tried INNER JOIN but no success. My code columns have no indices.
                        
First of all you should show also the structure of
table2to let us help you better.Otherwise, the error is due to the lack of
table1in your query. Ascodeis not present in yourINSERTstatement I may assume that it is an autoincrement field.Your query (I suppose, as I can't see the definition of
table2, as wrote before), could beIf the link between
table1andtable2is 1-to-many or many-to-many, just add aDISTINCTafter theSELECTkeyword to avoid duplicated results or change your query in