Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Databases

Jane Hazen
Jane Hazen
5,168 Points

SQL INSERT INTO() VALUES()

Why is this code not working:

-- Insert "Mark Hapka", "Jessica Rothe", "Eric Jungmann" and "Constance Wu" into the actors table.

INSERT INTO actors VALUES (NULL, "Mark Hapka"), (NULL, "Jessica Rothe"), (NULL, "Eric Jungmann"), (NULL, "Constance Wu");

If I add (id, name) after actors it still comes back saying "Query returned no results."

1 Answer

Steven Parker
Steven Parker
220,464 Points

Generally auto-increment ID fields are disregarded.

This is a bit of a guess since you did not refer to the course, but I'm guessing that "ID" is an auto-increment field. So you can disregard it entirely:

INSERT INTO actors (name)
  VALUES ("Mark Hapka"), ("Jessica Rothe"), ("Eric Jungmann"), ("Constance Wu");

If that's not it, please provide a link to the course page you are working with to enable a complete analysis.

Thanks, Steven. But why do we need separate parentheses for each name?

Steven Parker
Steven Parker
220,464 Points

Even though only one column is being filled, the parentheses identify that each entry represents an entire row.