Question: So I don't know if this is possible, but I would like to return the name of the column which has the closet value to my query.

So this is my table:

```
--------------------------
| ID | D1 | D2 | D3 | D4 |
--------------------------
| 1  | 0  | 10 | 22 | 50 |
--------------------------

```

I would like to do a query where I am searching in D1 to D4 for the closest value of 20, in this case D3

Then I would like to return D3 and the value in it.

So my answer should be: 

```
------
| D3 |
------
| 22 |
------

```

Is this by any way possible?

Answer: 
You can do this with a complicated `case`:

```
select (case least(abs(d1 - 20), abs(d2 - 20), abs(d3 - 20), abs(d4 - 20))
            when abs(d1 - 20) then 'd1'
            when abs(d2 - 20) then 'd2'
            when abs(d3 - 20) then 'd3'
            when abs(d4 - 20) then 'd4'
        end)
from mytable;

```

Note: This should have better performance than normalizing the data using `union all`. However, as a comment on the data structure, you probably want to store the values in separate rows rather than separate columns. Having separate columns with essentially the same values usually suggests the need for a junction table.
Have a look at something like <http://www.techfounder.net/2009/02/02/selecting-closest-values-in-mysql/>

What language are you using to echo out the data?