Question: I have list which contains a map List<Map<String, Object>> map has two keys which is a id and the amount. I want to sort the list descending order base on the amount key, if the amount is same for two elements in the list then sort it based on the id. How can I do this ?

```

    List<Map<String, Object>> list = new ArrayList<>();
    Map<String, Object> hm = new HashMap<>();
    hm.put(id, 1);
    hm.put(amount, 25000);
    list.add(hm);

```

index of list element = 1, 2, 3 ,4 ,5 ,6

values for id = 1, 2, 3 ,4 ,5, 4

values for amount = 10000, 450000, 25000, 45000, 35000, 75000

list should sorted as follows(index of list) = 6, 4 (id is large), 2, 5, 3, 1

Answer: 
Your model is not wrong as suggested in comments - your NetworkP2P might be missing only one column (Reciever), which could work as optional foreign key (to satisfy your sentence "Not all Phone numbers match the ones that Subscribers have."), but it looks more log than relational table.

Query for your desired output:

```
select
    caller.SubscriberID as Caller,
    reciever.SubscriberID as Reciever,
    caller.PhoneNumber as CallerPhone,
    nt.AddresseeNumber as RecieverPhone, -- better than reciever.PhoneNumber because you can use left join recievers to get missing substribers
    nt.CallStart,
    nt.CallEnd
from Subscriber as caller
inner join NetworkP2P as nt
    on nt.SubscriberID = caller.SubscriberID
inner join Subscriber as reciever
    on nt.AddresseeNumber = reciever.PhoneNumber
-- where '2021-02-03' between nt.CallStart and nt.CallEnd -- calls in 2021-02-03
-- where nt.CallStart between '2021-02-01' and '2021-02-28' -- calls in specific interval
-- where eomonth(nt.CallStart) = eomonth('2021-02-01') -- calls in specific month

```

You should always use database schema for all your tables (for example dbo.Subscriber).
Two joins to Subscriber should do it.

> 
> 
> ```
> SELECT 
>   nw.SubscriberID AS Caller
> , rcvr.SubscriberID AS Receiver
> , callr.PhoneNumber AS CallerPhone
> , nw.AddresseeNumber AS ReceiverPhone
> FROM NetworkP2P nw
> JOIN Subscriber callr ON callr.SubscriberID = nw.SubscriberID
> LEFT JOIN Subscriber rcvr ON rcvr.PhoneNumber = nw.AddresseeNumber
> WHERE rcvr.SubscriberID IS NOT NULL
> ORDER BY Caller, Receiver
> 
> ```
> 
> 

| Caller | Receiver | CallerPhone | ReceiverPhone |
| --- | --- | --- | --- |
| 1 | 3 | 613-555-0156 | 613-555-0119 |
| 1 | 4 | 613-555-0156 | 613-555-0182 |
| 2 | 1 | 613-555-0112 | 613-555-0156 |
| 2 | 3 | 613-555-0112 | 613-555-0119 |
| 3 | 2 | 613-555-0119 | 613-555-0112 |

Demo on *db<>fiddle [here](https://dbfiddle.uk/?rdbms=sqlserver_2017&fiddle=373815a6685d2fa4b842da4cbee26ace)*