开发者

MySQL One to Many Join?

I have 2 tables. 1 Table has pricing categories.

pricing :: id, pricing_name

The second table has pricing options

pricing_options :: id, parent, name, value

How do I select all of the values in the pricing table, then select all of pricing options so I would get an output like this?

开发者_Python百科

id [1], pricing_name [some name], pricing_options [ array containing options]


What do you mean with [array containing options]?

Supposing pricing_options.parent is a foreign key to pricing.id, you can try with:

SELECT id, pricing_name, name, value FROM pricing LEFT JOIN pricing_options ON pricing .id = pricing_options.parent;

This will give you all the pricings with they related pricing_options. You will have nulls on pricing_options part if there is no pricing_option for that pricing.

Hope it helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜