Skip to content
Advertisement

How to create/add a column in an SQL select query based on another column’s values?

I want to dynamically add another column hook_name, via an SQL select query, based on a condition.

For example if hook_type = 0, table hook_name should have a value of OFFER, and similarly for hook_type = 1, hook_name should show “ACCEPT”.

Below is a screenshot of the result:

enter image description here

The select query is this:

Thanks in advance.

Advertisement

Answer

Use a Standard SQL CASE:

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