Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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
229,670 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
229,670 Points

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