Mysql double select or inner join -


i have 2 mysql tables.

one of them stores general data product (name, image, description).

table name: product table fields: id, name, desc, brand, image, status 

the second 1 stores different variations products (size, color, price, promotion price).

table name: product_variation table fields: product_id, size, color, price, prom_price, status 

the thing don't realy know how display products first table ordered prices second table, considering in second table there more 1 rows same product id, different sizes, color , of course prices. default price field should considered, if there data larger 0 in prom_price field, prom_price should considered.

edit: result need 1 instance of every product first table, lowest possible price second table (from variations of product in second table)

select * product p inner join product_variation pv on p.id = pv.product_id order pv.prom_price, pv.price 

this duplicate product row many variants have (and show of these variants in related fields well). orders prom_price @ first , if it's 0 (or not unique) orders price.

edit: might want group p.id if want products kept together.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -