I'm a beginner of sql. I have a question about selecting specific row values.
Here's the data
| KEY | LOCATION | IDX |
| ---- | -------- | ---- |
| 01 | 1-01 | 0 |
| 01 | 1-02 | 1 |
| 01 | 1-03 | 2 |
| 02 | null | 0 |
| 02 | 2-02 | 1 |
| 02 | 2-03 | 2 |
| 03 | null | 0 |
| 03 | null | 1 |
| 03 | null | 2 |
and what am I expected:
| KEY | LOCATION | IDX |
| ---- | -------- | ---- |
| 01 | 1-01 | 0 |
| 02 | 2-02 | 1 |
| 03 | null | 1 |
for the same KEY, I want to get the value which IDX=0 and LOCATION is not null, and if not, return the value which IDX=1;
Is there any way to do that? I'm using sqlite3.
Appreciate the help!