Question: I am trying to add the text written in a textfield everytime and add it into an ArrayList. For eg- if the text "abcdef" is written in the textfield, then it should get added into the list. Again if the text "ghijkl" is written in the textfield, than that should get added.

My code for adding the text into the listview:

```
final ArrayList<String> mylist = new ArrayList<String>(5);
String s3=text1.getText().toString();
            if(s3!=null)
                g++;
            else g--;
            if(g>0) {
                for(int i=0;i<mylist.size();i++) {
                    mylist.add(s3);
                    Toast.makeText(getApplicationContext(), mylist.get(i), Toast.LENGTH_LONG).show();
                }
            }

```

Is this the right way to do this? Also I am trying to get the list item for testing purpose, but I don't get any toast.

Answer: 
Oracle solution:

```
with CTE as
(
select t1.*, 
       row_number() over(order by DBMS_RANDOM.VALUE) as rn -- random order assigned
from MyTable t1
where CPID <40
)
select *
from CTE
where rn <=5 -- pick 5 at random

union all
select t2.*, null
from my_table t2
where CPID >= 40

```

SQL Server:

```
with CTE as
(
select t1.*, 
       row_number() over(order by newid()) as rn -- random order assigned
from MyTable t1
where CPID <40
)
select *
from CTE
where rn <=5 -- pick 5 at random

union all
select t2.*, null
from my_table t2
where CPID >= 40

```
How about something like this...

```sql
SELECT *
FROM   (SELECT CID,
               CVAL,
               CPID,
               CPER,
               Row_number() OVER (partition BY CPID ORDER BY CPID ASC ) AS RN
        FROM   Table) tmp
WHERE  CPER>=40 OR pids <= 5

```

However, this is not random.