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

Shon Levi
Shon Levi
6,036 Points

Add SELECT to UPDATE query?

Hey guys,

Trying to make some query to work... I have email as variable and need to update all rows that the record in this row and above - means:

UPDATE quiz_1_highscore SET rate = rate - 1 WHERE rate >= ( SELECT rate FROM quiz_1_highscore WHERE email = ? )

Then I bind param for the email from a form submit, But This query isn't working...

I don't want to make 2 calls to the db - one to get the rate in that email row, and second to the update - Can I make it somehow in the same query???

Thanks!

1 Answer

Steven Parker
Steven Parker
231,140 Points

It sure looks like it should work.

:point_right: Did you remember to put quotes around the string that you are plugging into the space where that :question: mark is?