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

Only 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
Vittorio Somaschini
33,371 Points

Hi 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
Steven Parker
229,005 Points

I 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. :fishing_pole_and_fish:
    ― Maimonides

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hi Steven.

Right, but he was so close ...

;)

Thanks guys, the mysql syntax is just a little different than what i'm used to. "IN" expression has been covered too! Thank you!

Steven Parker
Steven Parker
229,005 Points

You can only combine complete expressions.

So for example, you can't write :point_right: team = "ATL" OR "BOS" OR "DEN"
but you could write :point_right: 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?