2

I was asking, but it misleading, so sorry for that. my problem is.

i have a table ranks(rank_id, rank_name, rank_min, rank_max)

is simple if i want know only one rank

select * from ranks where (224 between rank_min and rank_max)

but if want to know more than one rank, like what is 224, 338, 800, etc

i can use

select * from ranks where (224 between rank_min and rank_max) OR (338 between rank_min and rank_max) OR (800 between rank_min and rank_max)

but i dont know if may be there is simple way, like using

 IN(224,338,800)

and how to write a query in PHP that is not fix, i mean in solution 1, using many BETWEEN OR.

in PHP i know if it a siple query like select * from ranks where (224 between rank_min and rank_max). just pas the value. but i dont know how if more then one value

any body have trick and sample how to do that. i hope this question is not misleading

Thanks

1 Answer 1

2

I had an idea, I don't know if it's better than making the query dynamically with PHP, but it's worth a shot :

SELECT *
FROM ranks
INNER JOIN (SELECT unnest(ARRAY[224, 338, 800]) AS n) TT
    ON n BETWEEN rank_min AND rank_max;

You'd just have to make the array dynamically with PHP, but should be much easier than making the whole query.

Sign up to request clarification or add additional context in comments.

3 Comments

owh got, it just an alias name, i dont mention because i dont see 'AS TT'
hi Vincent. how if want use GROUP BY. ex : SELECT * FROM ranks INNER JOIN (SELECT unnest(ARRAY[224, 338, 800]) AS n) TT ON n BETWEEN rank_min AND rank_max GROUP BY rank_id;
@Thessa: What are you trying to do with GROUP BY?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.