Frederik
Frederik

Reputation: 3

Merge/combine fields from two database tables

I have two tables in my database which I want to join some matching results from.

ps_product (column names): id_product | reference | price | wholesale_price
ps_stock (column names): id_product | quantity

I would like to combine these two tables to get:

Table: id_product | reference | quantity | price | wholesale_price

Both tables have matching id_product values and should be matched, so quantity fits the right reference and so forth. Saved to a csv file if possible.

Running mysql on Debian.

Thank you in advance!

Upvotes: 0

Views: 33

Answers (1)

Abhik Chakraborty
Abhik Chakraborty

Reputation: 44864

You can do inner join as

select 
p.id_product,
p.reference,
s.quantity,
p.price,
p.wholesale_price
from ps_product p
join ps_stock s on s.id_product = p.id_product

Upvotes: 1

Related Questions