Why doesnt it show me the amount of authors who wrote more than 1 book? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why doesnt it show me the amount of authors who wrote more than 1 book?

CREATE TABLE books(catalog TEXT , name VARCHAR(20), author VARCHAR(20), publisher VARCHAR(20) , year YEAR , pages INT , price DOUBLE , PRIMARY KEY(catalog)); insert into books values ('1234', 'War and Peace', 'Leo Tolstoy','Keshet', 1982, 1255, 102.5); insert into books values ('2365', 'Skeleton Crew','Stephen King', 'Harper Collins', 1986, 563, 86.99); insert into books values ('2233', 'Liseys Story','Stephen King', 'Penguin', 2006, 456, 88.0); insert into books values ('4455', 'Anna Karenina','Leo Tolstoy', 'Penguin', 2006, 963, 129.99); insert into books values ('4545', 'A Tale Of Love And Darkness','Amos Oz', 'Penguin', 1986, 850, 117.99); insert into books values ('1352', 'Desperation','Stephen King', 'Harper Collins', 2011, 365, 79.99); insert into books values ('8657', 'Harry Potter and the philosophers stone','J.K Rowling', 'Scholastic Press', 1997, 309, 72.23); insert into books values ('5754', 'The Wave','Todd Strasser', 'Dell', 1981, 146, 20.99); insert into books values ('9781', 'Percy Jackson','Rick Riordan', 'Disney Hyperion', 2005, 200, 59.99); insert into books values ('7825', '1984','George Orwell', 'Harvill Secker', 1949, 328, 36.80); insert into books values ('4376', 'The Lottery','Shirley Jackson', 'The New Yorker', 1948, 32, 20.04); SELECT author FROM books WHERE 1 < (SELECT COUNT(*) FROM books GROUP BY author);

11th Sep 2020, 3:24 PM
Yahel
Yahel - avatar
2 Answers
0
Your subquery returns more than 1 value and cannot be used correctly with < operator You should use HAVING clause: SELECT author FROM books GROUP BY author HAVING COUNT(*) > 1;
11th Sep 2020, 6:19 PM
gambler
0
gambler , oh yeh... thanks!
11th Sep 2020, 6:20 PM
Yahel
Yahel - avatar