Stecy Aulia
Stecy Aulia

Reputation: 65

mysql select between or what?

I'm learning about MySQL and I have a case, I have some table like this:

id, level,        minpost, maxpost
 1, 'Newbie',           0,      99
 2, 'Enthusiast',     100,     499
 3, 'Activist',       500,     749
 4, 'Socialite',      750,     999

So how do I know which "level" if I have 80 posts?

Should I use select between or maybe you have any suggest for my problem?

ps. I cant post image :(

Upvotes: 0

Views: 1020

Answers (4)

Harry Joy
Harry Joy

Reputation: 59660

Yes you can use BETWEEN.

It's nothing but the short form of value>=minvalue AND value<=maxvalue

The query will look like:

select * from `tableName`
   where <valueToCheck> between minpost AND maxpost;

Upvotes: 0

shashuec
shashuec

Reputation: 694

select id,level from <table> where minpost >= <minpost> and maxpost <= <maxpost>

Upvotes: 0

user330315
user330315

Reputation:

select *
from the_table
where 80 between minpost AND maxpost

P.S.: don't bother posting images, SQL code (that can be copied) is much better

Upvotes: 0

jensgram
jensgram

Reputation: 31508

SELECT level FROM <table> WHERE <myLevel> BETWEEN minpost AND maxpost

The BETWEEN operator will do the following:

expr BETWEEN min AND max

Equals:

(min <= expr AND expr <= max)

Upvotes: 5

Related Questions