onlyican Posted September 16, 2006 Share Posted September 16, 2006 HeyI have multiple tables, and I want to run a query on 2 tables in oneThe DB's are set out like so##DB 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)## DB 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)As you can see in both tables, I have prod_idThis is a number i enter and is relevant to another table holding the product nameI have put 2 examples in the tables, different informatiom, then try running this querrySELECT stock.in_stock, prices.buy_price, prices.iva, prices.re, prices.total_price, prices.sell_price FROM products, stock, prices WHERE stock.prod_id = '3' AND prices.prod_id = '3'This works okExcept its returning 2 rows, Both the same data, the data I want which is relevant to prod_id being 3, but 2 rows(I am using MySQL-Front to test the queries before building them in the script)I know I can add LIMIT to the query, but will this query be ok when running against 1000 rows of data? Link to comment https://forums.phpfreaks.com/topic/20981-help-with-query/ Share on other sites More sharing options...
fenway Posted September 16, 2006 Share Posted September 16, 2006 You're mising a join condition on the products table. Link to comment https://forums.phpfreaks.com/topic/20981-help-with-query/#findComment-93270 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.