I have a table ABR with three columns: two lookup values, A and B and a result Result. I want the result to be returned given A and B
But, for some values of A, column B can be a wildcard. In that case I want the most specific row.
I can’t seem to figure out the MySQL statement though – I found one, but it was 7 lines long and had 5 = and two IF‘s, there must be a better way.
A B Result
1 * First
2 * Second
2 1 Third
2 2 Fourth
3 * Fifth
Example wanted results:
A=1, B=5 -> First
A=1, B=0 -> First
A=2, B=2 -> Fourth
A=2, B=4 -> Second
A=3, B=7 -> Fifth
Do notice that the column values can change later: we can add extra rows for A and B, or remove values. Hardcoding stuff in the SQL is not acceptable.
1 Answer