Question: I have a sample df

```
id        name
 1        John Walter walter
 2        Adam Smith Smith
 3        Steve Rogers rogers

```

How can I find whether it is duplicated in every row and pop it out?

```
id        name                    is_duplicated    poped_out_string     corrected_name
 1        John Walter walter             1               walter             John walter
 2        Adam Smith Smith               1               walter             Adam Smith
 3        Steve Rogers rogers            1               walter             Steve Rogers

```

Answer: 
First, query `ids` where `category` is completed:

```sql
select
    category,
    array_agg(id) as ids
from tbl
group by category
having bool_and(nullif(data_1, '') || nullif(data_2, '') is not null) 
order by category;

 category |   ids
----------+---------
        1 | {1,2}
        5 | {13,14}
        6 | {15}
(3 rows)

```

Use this as a derived table to search `ids` matching the input list:

```sql
select category
from (
    select
        category,
        array_agg(id) as ids
    from tbl
    group by category
    having bool_and(nullif(data_1, '') || nullif(data_2, '') is not null) 
    ) s
where ids && array[1, 5, 12, 13, 14] -- input parameter
order by category;

 category
----------
        1
        5
(2 rows)

```

Test it in [db<>fiddle](https://dbfiddle.uk/HmKoaJkn).

Alternative solution using the `bool_and()` aggregate as a window function:

```sql
select distinct category
from (
    select 
        id, 
        category,
        bool_and(nullif(data_1, '') || nullif(data_2, '') is not null) over w as completed
    from tbl
    window w as (partition by category)
    ) s
where completed
and id = any(array[1, 5, 12, 13, 14]) -- input parameter
order by category;

```
```
select distinct category from tbl 
where category not in (
select category from tbl
where data_1 is null or data_1 = ''
or  data_2 is null or data_2 = '')

```

Fixed using your fiddle!