简体   繁体   中英

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM