I have created a data frame in Python like given below
df = pd.DataFrame({'status': ["Applied", "Applied", "NotApplied", "Applied", "NotApplied", "Applied", "Applied"],
'date1': ["2022-02-02", "2022-03-10", np.nan, np.nan, "2022-02-25", "2022-01-16", np.nan],
'date2':["2022-02-02", "2022-03-10", "2022-02-14", "2022-01-05", "2022-02-25", "2022-01-16", "2022-02-16"]})
df['date1'] = pd.to_datetime(df['date1'], format='%Y-%m-%d')
df['date2'] = pd.to_datetime(df['date2'], format='%Y-%m-%d')
| status | date1 | date2 | |
|---|---|---|---|
| 0 | Applied | 2022-02-02 00:00:00 | 2022-02-02 00:00:00 |
| 1 | Applied | 2022-03-10 00:00:00 | 2022-03-10 00:00:00 |
| 2 | NotApplied | NaN | 2022-02-14 00:00:00 |
| 3 | Applied | NaN | 2022-01-05 00:00:00 |
| 4 | NotApplied | 2022-02-25 00:00:00 | 2022-02-25 00:00:00 |
| 5 | Applied | 2022-01-16 00:00:00 | 2022-01-16 00:00:00 |
| 6 | Applied | NaN | 2022-02-16 00:00:00 |
And then applied the below code
df.loc[ (df['status'] == 'Applied') , 'date1'] = df['date2']
df = df[df['status'] == 'Applied']
| status | date1 | date2 | |
|---|---|---|---|
| 0 | Applied | 2022-02-02 00:00:00 | 2022-02-02 00:00:00 |
| 1 | Applied | 2022-03-10 00:00:00 | 2022-03-10 00:00:00 |
| 3 | Applied | 2022-01-05 00:00:00 | 2022-01-05 00:00:00 |
| 5 | Applied | 2022-01-16 00:00:00 | 2022-01-16 00:00:00 |
| 6 | Applied | 2022-02-16 00:00:00 | 2022-02-16 00:00:00 |
Question
How should I write the above 2 lines of code in SQL using only a select statement (I don't want to alter or update the current table in SQL).