Skip to content
Advertisement

How to select row values conditionally and change them to custom columns?

I have two tables orders, product_meta that are as follows:

orders:

product_meta:

I want a table like this:

The query that I have tried:

but this only works for one field(name) so how can I modify this so as to include price and other meta values?

Advertisement

Answer

One method is two joins:

This uses left joins so all orders will be included, even if the metadata is missing either name or price or both.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement