Previously this function would output invalid SQL as a logical
operator would be included after every condition. This change
removes the final logical operator so the SQL is valid.
For example, previously the single rule:
`bgpPeers.bgpPeerRemoteAs = "6939" &&"`
Would generate:
```
SELECT DISTINCT(bgpPeers.device_id) FROM bgpPeers WHERE device_id=? && (bgpPeers.bgpPeerRemoteAs = "6939" &&) LIMIT 1
```
This changes means it will generate:
```
SELECT DISTINCT(bgpPeers.device_id) FROM bgpPeers WHERE device_id=? && (bgpPeers.bgpPeerRemoteAs = "6939") LIMIT 1
```
Currently the function for retrieving device_groups returns rows in the order
in which they were created. This causes the WebUI to display is a semi-random
order. This patch causes the devices to be sorted by name which makes the
group lists easier to navigate.