I have two tables which I need to join depending upon their values.

```
TABLE coursemat
+-----+--------+----------+
| txt | price  | material |
+-----+--------+----------+

Table coprices
+--------+----------+
| price  | material |
+--------+----------+

```

They are connected by the `material` key. 

If I search `coursemat.material` and find that `coprices.material` is equal, then I must use `coprices.price` instead of the `coursemat.price`.

This is what I have so far:

```
SELECT coursemat.txt, coursemat.price, coursemat.material, coprices, country
FROM coursemat
JOIN corprices ON coursemat.material = coprices.material;

```

But this isn't quite getting what I want.

Essentially, I want to use `coursemat.price` if `coprices.price` does not exist for the same material and `coprices.material` does exist, then I want to use `coprices.price` instead of `coursemat.price`.