Mark
Mark

Reputation: 9

Select rows based on value between 2 fields

I have table in SQL Server 2008:

CREATE TABLE [ValueDB](
[min_price] [float] NULL,
[max_price] [float] NULL
) 

Now, I have this number 250, I need to select the rows where 250 is between min_price and max_price

Upvotes: 0

Views: 201

Answers (5)

Narnian
Narnian

Reputation: 3908

If I understand your question correctly, this is all you would need to return all rows where the min price is below 250 and the max price is above 250.

SELECT *
FROM [ValueDB]
WHERE [min_price] < 250 AND [max_price] > 250

Upvotes: 0

bpgergo
bpgergo

Reputation: 16057

select * from valuedb where 250 between min_price and max_price

Upvotes: 0

JNK
JNK

Reputation: 65217

SELECT *
FROM ValueDB
WHERE 250 BETWEEN min_Price AND max_Price

Upvotes: 0

Joe Stefanelli
Joe Stefanelli

Reputation: 135938

Your pseudo-code description is 99% of what you need.

SELECT *
    FROM ValueDB
    WHERE 250 BETWEEN min_price AND max_price

Upvotes: 0

Colin
Colin

Reputation: 2021

Something as simple as this:

SELECT * from ValueDB WHERE min_price < 250 AND max_price > 250

Upvotes: 2

Related Questions