Jump to content

Help with Query


onlyican

Recommended Posts

Hey

I have multiple tables, and I want to run a query on 2 tables in one

The 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_id
This is a number i enter and is relevant to another table holding the product name

I have put 2 examples in the tables, different informatiom, then try running this querry
SELECT 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 ok
Except 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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.