Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It sounds like you want to use something similar to this:</p> <pre><code>select id from yourtable group by `group` having count(`group`) = 1 </code></pre> <p>See <a href="http://www.sqlfiddle.com/#!2/8ce31/7" rel="nofollow">SQL Fiddle with Demo</a>.</p> <p>Then if you want to return all details, then you can expand the query to:</p> <pre><code>select * from yourtable t1 where id in (select id from yourtable t2 group by `group` having count(`group`) = 1) </code></pre> <p>See <a href="http://www.sqlfiddle.com/#!2/8ce31/4" rel="nofollow">SQL Fiddle with Demo</a>.</p> <p>If you want to return all rows that have the same group, then you can use:</p> <pre><code>select * from yourtable t1 where `group` in (select `group` from yourtable t2 group by `group` having count(`group`) &gt; 1) </code></pre> <p>See <a href="http://www.sqlfiddle.com/#!2/9ff21/11" rel="nofollow">SQL Fiddle with Demo</a></p> <p>Then if you want to return everything and a flag that identifies if it is a single or multiple, then you can use something similar to this. You will notice that I included a flag to show what <code>groups</code> have one row and then what groups have more than one row:</p> <pre><code>select *, 'single' Total from yourtable t1 where `group` in (select `group` from yourtable t2 group by `group` having count(`group`) = 1) union all select *, 'multiple' Total from yourtable t1 where `group` in (select `group` from yourtable t2 group by `group` having count(`group`) &gt; 1) </code></pre> <p>See <a href="http://www.sqlfiddle.com/#!2/9ff21/13" rel="nofollow">SQL Fiddle with Demo</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload