I am using Codeigniter, I have two tables. From the first table bank_id, I am sending in the second table f_bankid.
1) tbl_bankdata
bank_id | b_bankname | lead_id
1       | 1          | 197
2       | 2          | 197
3       | 3          | 197
4       | 1          | 196
5       | 2          | 196
6       | 3          | 196
7       | 1          | 196
8       | 2          | 196
2) tbl_fileStatus
f_id | f_date      | f_remark        |f_bankid  | f_filestatus| f_dateofadded
1    | 2020-03-29  |This is testing1 |  1       | 6           | 2020-03-28 19:28:50 
2    | 2020-03-30  |This is testing2 |  2       | 6           | 2020-03-28 19:28:50 
3    | 2020-03-30  |This is testing3 |  3       | 6           | 2020-03-28 19:28:50 
4    | 2020-03-30  |Testing for pend |  1       | 3           | 2020-03-29 01:00:04 
5    | 2020-03-29  |Testing1         |  4       | 6           | 2020-03-29 05:22:09 
6    | 2020-03-29  |Testing2         |  5       | 6           | 2020-03-29 05:22:09 
7    | 2020-03-30  |Testing3         |  6       | 6           | 2020-03-29 05:22:09
8    | 2020-03-30  |Testing4         |  7       | 6           | 2020-03-29 05:22:09
9    | 2020-03-30  |Testing5         |  8       | 6           | 2020-03-29 05:22:09 
10   | 2020-03-30  |Testing for OD   |  4       | 4           | 2020-03-29 10:54:46 
Now notice in the second table, I have more one same bank_id.
For example
f_id | f_date      | f_remark        |f_bankid  | f_filestatus| f_dateofadded
1    | 2020-03-29  |This is testing1 |  1       | 6           | 2020-03-28 19:28:50 
4    | 2020-03-30  |Testing for pend |  1       | 3           | 2020-03-29 01:00:04 
5    | 2020-03-29  |Testing1         |  4       | 6           | 2020-03-29 05:22:09 
10   | 2020-03-30  |Testing for OD   |  4       | 4           | 2020-03-29 10:54:46 
So I have to display the last record added and the output will be as below
4    | 2020-03-30  |Testing for pend |  1       | 3           | 2020-03-29 01:00:04 
10   | 2020-03-30  |Testing for OD   |  4       | 4           | 2020-03-29 10:54:46 
I am using below query but not getting my expected output
  $lead_id=$lead->c_id;
  $bank = $this->db->select('*')
               ->from('tbl_bankdata')
               ->join('tbl_fileStatus','tbl_bankdata.bank_id=tbl_fileStatus.f_bankid')
               ->where('tbl_bankdata.lead_id', $lead_id)
               ->group_by('tbl_fileStatus.f_bankid')
               //->order_by('tbl_fileStatus.f_dateofadded','DESC')
               ->get()
               ->result();
My expected output is
  bank_id | b_bankname | lead_id |f_id | f_date      | f_remark        |f_bankid  | f_filestatus| f_dateofadded
    1     | 1          | 197     |4    | 2020-03-29  |Testing for pend | 1        | 3          |2020-03-29 01:00:04
    2     | 2          | 197     |2    | 2020-03-30  |This is testing2 | 2        | 6          |2020-03-28 19:28:50
    3     | 3          | 197     |3    | 2020-03-30  |This is testing3 | 3        | 6          |2020-03-28 19:28:50
    4     | 1          | 196     |10   | 2020-03-30  |Testing for OD   | 4        | 4          |2020-03-29 10:54:46
    5     | 2          | 196     |6    | 2020-03-29  |Testing2         | 5        | 6          |2020-03-29 05:22:09
    6     | 3          | 196     |7    | 2020-03-30  |Testing3         | 6        | 6          |2020-03-29 05:22:09 
    7     | 1          | 196     |8    | 2020-03-30  |Testing4         | 7        | 6          |2020-03-29 05:22:09
    8     | 2          | 196     |9    | 2020-03-30  |Testing5         | 8        | 6          |2020-03-29 05:22:09
And records should remove using the query
f_id | f_date      | f_remark        |f_bankid  | f_filestatus| f_dateofadded
1    | 2020-03-29  |This is testing1 |  1       | 6           | 2020-03-28 19:28:50 
5    | 2020-03-29  |Testing1         |  4       | 6           | 2020-03-29 05:22:09 
