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 trialMatt Caminiti
3,466 PointsOnly showing first result from "WHERE" clause.
Hi, i'm trying to query some data from my built database and for some reason i'm only able to retrieve what is outlined first in the where clause.
EX - SELECT Name, team, PPG FROM player_stats WHERE team = "ATL" OR "BOS" OR "DEN";
I'm able to see all information requested, but only for players from "ATL" or Atlanta. Is there any reason as to why this is happening? Same thing happens when attempting to join tables as well.
Any info would be greatly appreciated. Thank you!
2 Answers
Vittorio Somaschini
33,371 PointsHi Matt,
Have you tried?
SELECT Name, team, PPG FROM player_stats WHERE team = "ATL" OR team = "BOS" OR team = "DEN";
OR (probably better):
SELECT Name, team, PPG FROM player_stats WHERE team in ("ATL" "BOS" "DEN");
Let me know
Vitto
Steven Parker
231,271 PointsYou can only combine complete expressions.
So for example, you can't write team = "ATL" OR "BOS" OR "DEN"
but you could write team = "ATL" OR team = "BOS" OR team = "DEN"
.
But in this case, you might want to take advantage of a different kind of expression that uses multiple terms. Has the course covered the use of "IN
" yet?
Steven Parker
231,271 PointsSteven Parker
231,271 PointsI was thinking Matt might like to try solving this for himself using a few hints instead of getting a complete answer.
Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime.
― Maimonides
Vittorio Somaschini
33,371 PointsVittorio Somaschini
33,371 PointsHi Steven.
Right, but he was so close ...
;)
Matt Caminiti
3,466 PointsMatt Caminiti
3,466 PointsThanks guys, the mysql syntax is just a little different than what i'm used to. "IN" expression has been covered too! Thank you!