How to find duplicate names from table?
<p>I know we can use <code>GROUP BY</code> and <code>HAVING COUNT &gt; 1</code>. But this works when you have duplicate data. I have a little bit different data.</p>

<pre><code>Id Names
1  Rahul S
2  Rohit S
3  Rishu
4  Sinu
5   Rahul S
6  Rohit  S
</code></pre>

<p>In the above table id 1 and 5 are same and 2 and 6 are also same. But when I use group by it count as different because of spaces. So how can I write a query with fuzzy logic something which will return these kind of duplicate datas.</p>

<p>**Update</p>

<p>Can someone help me with a query which will remove spaces from a particular column and add a imaginary column on that we can group by having count > 1</p>

<p><code>SELECT replace(ltrim(rtrim(name)),' ','') as no_space FROM table GROUP BY no_space HAVING count(*) &gt; 1 ORDER BY no_space;</code></p>

<p>You can use the REPLACE function to remove white spaces. </p>

<p>I would save the string without spaces into a new column and use the group by on that.
Like:</p>

<pre><code>Select &lt;values you are looking for&gt;, replace(Names, ' ', '') as d 
from &lt;Table name&gt; 
group by d
</code></pre>

python psql peewee