I have two table,the names table and the earnings table.
| Name_ID | Name_desc |
| ------------ | ------------ |
| 1 | mark |
| 2 | smith |
| 3 | becky |
| 4 | jimmy |
and the earnings table
ID_1 | Earnings_1 | ID_2 | Earnings_2 | ID_3 | Earnings_3 | ID_4 | Earnings_4 |
---|---|---|---|---|---|---|---|
1 | 500 | 2 | 5454 | 3 | 1247 | 4 | 7844 |
You can try it out here:
Question: How to join Name_ID and ID_ to get the earnings. I need a funtion to check every ID column in the earnings table and if it match then get the earnings.
The goal is a table that looks like this:
| Name_ID | Name_desc | earnings |
| ------------ | ------------ | ------------ |
| 1 | mark | 500 |
| 2 | smith | 5454 |
| 3 | becky | 1247 |
| 4 | jimmy | 7844 |
2条答案
按热度按时间qpgpyjmq1#
DBFiddle
kwvwclae2#