Given Table\_1:

```
| testing | main_val |
| AB      | VAL      |
| EF      | DIP      |

```

and Table\_2:

```
| main_val | for_testing |
| VAL      |             |
| VAL      | AB          |
| VAL      | CD          |
| DIP      |             |
| DIP      | GH          |

```

My join query is below:

```
select table1.testing, table1.main_val, table2.for_testing from table_1 table1
inner join table_2 table2 on table1.main_val = table2.main_val

```

I get the following result:

```
| testing | main_val | for_testing |
| AB      | VAL      |             |
| AB      | VAL      | AB          |
| AB      | VAL      | CD          |
| EF      | DIP      |             |
| EF      | DIP      | GH          |

```

My requirement is to get the best "testing match". If the testing and for\_testing columns match, then I should retrieve that row. If no matches, choose the empty for\_testing row. I need the result to look like:

```
| testing | main_val | for_testing |
| AB      | VAL      | AB          |
| EF      | DIP      |             |

```

More columns will be added for this join, that is why getting the best match row is important.