1

I have a table like this:

enter image description here

Each keyword should have 4 pieces of data.

I want to select the keywords that have less than 4 pieces of data (less than 4 rows).

I used select count(*) from mytable group by keyword to achieve something like this:

enter image description here

how can I select the keywords based on the count(*) result?

Here I want the keyword b from the result grid.

Hannah Vernon
  • 70,041
  • 22
  • 171
  • 315
Rick
  • 115
  • 6

1 Answers1

2

You can either nest your select and use a where clause in the outer select:

select keyword 
from (
    select keyword, count(*) as cnt
    from mytable
    group by keyword
) as t
where cnt < 4

or you can use having which essentially is a shorter form of the above:

select keyword
from mytable
group by keyword
having count(*) < 4
Lennart - Slava Ukraini
  • 23,240
  • 3
  • 32
  • 69