2

I have to print out only the publishers that published more than 2 books, but for my results, I always get

PUB_NAME            |TOTAL      
--------------------------------
Abatis Publishers   |4          
Core Dump Books     |1     <------don't want to print     
Schadenfreude Press |3          
Tenterhooks Press   |5   

ERROR 42X01: Syntax error: Encountered "HAVING"

This is my code so far.

SELECT pub_name, COUNT(title_name) AS total
FROM publishers 
INNER JOIN titles
ON titles.pub_id = publishers.pub_id
GROUP BY pub_name;
HAVING total > 2;
Matt
  • 14,906
  • 27
  • 99
  • 149
Jake
  • 313
  • 1
  • 7
  • 16

2 Answers2

2

total is not recognize in HAVING. Try HAVING COUNT(title_name) > 2;

Also remove the ';' in GROUP BY pub_name;

JFPicard
  • 5,029
  • 3
  • 19
  • 43
0

Just use WHERE

SELECT p.pub_name, COUNT(t.title_name) AS total
FROM publishers p
INNER JOIN titles t ON t.pub_id = p.pub_id
WHERE COUNT(t.title_name) > 2
GROUP BY p.pub_name;
Matt
  • 14,906
  • 27
  • 99
  • 149