Jump to content

Archived

This topic is now archived and is closed to further replies.

DaveLinger

Select where row=value OR where row=value?

Recommended Posts

here's the deal. I'm still working on the game review site. Each review has a section id, (2 digits, like "12") which are related to which platforms the game is on. An example:

12 - PS2
13 - Xbox
14 - PC
15 - PS2 and Xbox
16 - PS2 and Xbox and PC
17 - Xbox and PC

I have 2 lists of reviews, one for Xbox games, one for PS2 games. I was hoping to have MySQL select the results of rows with EITHER "12" OR "15" OR "16" on the PS2 list, so that on the Xbox list I could have it select 13 15 16 and 17. Is there an easy way to add this into my existing code? right now it's something like:

SELECT * FROM my_table WHERE sid = '12' ORDER BY title DESC

Share this post


Link to post
Share on other sites
do you have a field that contains the game type, like PS2, Xbox, or PC?
something like this:

sid    types:
12    PS2
13    Xbox
14    PC
15    PS2,Xbox
16    PS2,Xbox,PC


u know? it's much easier if you have a field in database which indicated the type of games for each review. 

Share this post


Link to post
Share on other sites
it is matter because you don't have to remember: id 12 is ps2, id 13 is xbox. u know

say you got a field called types, you can organize your query like this:

... where types like '%xbox%';

and it will return all row which contain xbox.

Share this post


Link to post
Share on other sites
SELECT * FROM my_table  WHERE sid IN (12,15,16) ORDER BY title DESC

Share this post


Link to post
Share on other sites
PS: Checking indexes/numbers is much faster than wildcard search, you should avoid it if unneccesary.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.