
Gia Hoang Nguyen
4,117 PointsCant write the correct query. Need help
It keeps giving error "Was expecting 4 entries in the products table. There's only 3.
Please help
Thanks
4 Answers

Jonathan Whittle
27,679 PointsI assume you're referring to task 1 of the challenge? Here's one option:
INSERT INTO products (name, description, price) VALUES ('coffee', 'dark roast', 10);
After naming the table 'products', I listed the column names that I wished to add values for, then the values themselves.. It says that they database is set to auto increment, so you don't need to supply the ID number. The challenge is looking for 4 new values (id, name, description, price). The following code doesn't work:
INSERT INTO products VALUES ('coffee', 'dark roast', 10);
The previous code is trying to add 'coffee' to the ID column of the table. The ID column is set to integer, meaning it can only accept numbers, not text. Since the database is set to auto-increment, I specified which columns I wanted to add values for and the ID updated automatically.

Joni Whitworth
1,425 PointsMine is not working either. Can anyone help? I have:
INSERT INTO products (id, name, description, price) VALUES ("2", "Raven", "shirt", "$20");

Joni Whitworth
1,425 PointsI am also getting the same error: "Was expecting 4 entries in the products table. There's only 3."

KRIS NIKOLAISEN
Pro Student 51,836 PointsWhen specifying columns by name you don't need to include the auto-incrementing primary key. Try this:
INSERT INTO products (name, description, price) VALUES ("Raven", "shirt", "$20");

Joni Whitworth
1,425 PointsOh, that worked. Thank you!
KRIS NIKOLAISEN
Pro Student 51,836 PointsKRIS NIKOLAISEN
Pro Student 51,836 PointsAre you using the following syntax:
INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);