onlyican Posted September 18, 2006 Share Posted September 18, 2006 Hey guysI am learning this Join stuff, WickedI got the hang of INNER JOIN for SELECTbutI have 3 tables, and I want to insert data in all 3, without doing 3 queriesI tried thisINSERT INTO products LEFT JOIN prices on products.id_num = prices.prod_id LEFT JOIN stock on products.id_num = stock.prid_id (ref_num, prod_name, suppliers, cat, sub_cat, buy_price, iva, re, total_price, sell_price, stock_level, in_stock) VAlUES('1006', 'Cat Food', '3', 'Cat', 'Food' '8.15', '0', '0', '8.15', '10.20', '5', '5');but I got an error on Inner the Inner JoinNOTE: this is dummy information, like a shop will buy something for 8.15 and sell it for 10.20)All this information is coming from a formHere is the table information for the 3 tablesCREATE TABLE IF NOT EXISTS products ( id_num int(50) unsigned NOT NULL auto_increment, ref_num varchar(10) DEFAULT '0' , prod_name varchar(150) DEFAULT '0' , supplier varchar(50) DEFAULT '0' , cat varchar(150) , sub_cat varchar(150) , PRIMARY KEY (id_num));CREATE TABLE IF NOT EXISTS prices ( id_num int(50) NOT NULL auto_increment, prod_id int(50) DEFAULT '0' , buy_price double(5,2) DEFAULT '0.00' , iva int(3) unsigned DEFAULT '0' , re double(2,1) DEFAULT '0.0' , total_price double(5,2) DEFAULT '0.00' , sell_price double(5,2) DEFAULT '0.00' , PRIMARY KEY (id_num));CREATE TABLE IF NOT EXISTS stock ( id_num int(50) unsigned NOT NULL auto_increment, prod_id int(50) unsigned DEFAULT '0' , stock_level tinyint(5) DEFAULT '0' , in_stock tinyint(5) DEFAULT '0' , PRIMARY KEY (id_num));The Connection between the 3 isprod_id in tables Stock and prices is the same as id_num in productsAnyone who can help, Many Thanks Quote Link to comment Share on other sites More sharing options...
fenway Posted September 18, 2006 Share Posted September 18, 2006 You have no choice but to issue one insert statment per table. Quote Link to comment Share on other sites More sharing options...
onlyican Posted September 18, 2006 Author Share Posted September 18, 2006 I thought Joins work on INSERT and UPDATEor is it only on SELECT with MySQL Quote Link to comment Share on other sites More sharing options...
fenway Posted September 20, 2006 Share Posted September 20, 2006 Only SELECT... though you can "use" it with INSERT INTO... SELECT WHERE. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.