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

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
216,148 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
216,148 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?