Say I have a table named people with various attributes
- first name
- last name
- age
- phone
- address
- ...
I would like to make a query that will return all people, however, under a certain condition (a separate subquery) I would like for certain columns of the select statement to be set to null for redacting purposes.
So, say I have the basic query:
SELECT first_name, last_name, age, phone, address
FROM people;
Which would return a table similar to:
|first_name|last_name|age|phone|address |
------------------------------------------------
|Joe |Someone |12 |123 |1234 Somewhere|
|Bob |Other |45 |982 |4321 Somewhere|
I would like to be able to do something like this:
SELECT
first_name,
last_name,
if(people.field IN (
SELECT other_table.some_id FROM other_table WHERE other_table.field = 'is good')
)
age, phone, address
else
NULL
FROM people;
With the result I would like to have:
|first_name|last_name|age |phone|address |
------------------------------------------------
|Joe |Someone |12 |123 |1234 Somewhere|
|Bob |Other |NULL |NULL |NULL |
Is this even possible?