Question: Hi I have been following the [tutorials in youtube](https://www.youtube.com/watch?v=DKuGU5CYV_E&t=159s) it uses CLI container to add an org. Since using CLI container is not recommended to have in production environment how to add an org into the existing network withput using cli container

Answer: 
try this

```
WITH CTE
AS
(
    SELECT
        SeqNo = ROW_NUMBER() OVER(PARTITION BY LastName,FirstName ORDER BY DateTo DESC),
        *
        FROM Guests
)
SELECT
*
FROM CTE
    WHERE SeqNo = 1

```

This query will return the latest records for each user, if there are multiple records for a first name + last name combination, it will give you the latest one based on dateTo otherwise it will return the record as it is

So you will get only 1 row per guest each time you execute this
Try: 

```
SELECT
A.LASTNAME, A.FIRSTNAME, A.DATEFROM, A.DATETO, A.ROOMNUMBER, A.CITY, A.COUNTRY, A.STATUS, A.DAYS
FROM
(SELECT LASTNAME, FIRSTNAME, MAX(DATETO) AS MOST_RECENT_STAY
FROM YOUR_TABLE 
GROUP BY LASTNAME, FIRSTNAME) Z
INNER JOIN
YOUR_TABLE A
ON Z.LASTNAME = A.LASTNAME AND Z.FIRSTNAME = A.FIRSTNAME AND Z.MOST_RECENT_STAY = A.DATETO;

```