Vinoth Kumar
Vinoth Kumar

Reputation: 93

i want to give price range from this query result give me a correct query

i want to give price range from this query result give me a correct query

SELECT id,tableid,category,price,actualprice,image,title,website,description 
FROM tt_1 
where 
       title like 'Home Appliances%' or 
       image like 'Home Appliances%' or 
       category like 'Home Appliances%' or 
       site_master_url like 'Home Appliances%' or 
       website like 'Home Appliances%' 

Upvotes: 0

Views: 441

Answers (4)

redmoon7777
redmoon7777

Reputation: 4526

I will keep the same logic you have there (I think you should be using AND not OR if you are filtering data but you would know better what you need) this will fetch price between 100-1000:

SELECT id,tableid,category,price,actualprice,image,title,website,description FROM tt_1 where title like 'Home Appliances%' or image like 'Home Appliances%' or category like 'Home Appliances%' or site_master_url like 'Home Appliances%' or website like 'Home Appliances%' or (price > 100 AND price < 1000)

Upvotes: 1

gbn
gbn

Reputation: 432210

Does no-one in the other answers understand operator precedence?

SELECT id,tableid,category,price,actualprice,image,title,website,description 
FROM tt_1 
where 
    (
       title like 'Home Appliances%' or 
       image like 'Home Appliances%' or 
       category like 'Home Appliances%' or 
       site_master_url like 'Home Appliances%' or 
       website like 'Home Appliances%' 
    )
    AND
    price BETWEEN @LowerBound AND @UpperBound;

Last line could be this too (parenthesis for clarity):

    AND
    (price >= @LowerBound AND price <= @UpperBound)

Upvotes: 1

Subhojit Mukherjee
Subhojit Mukherjee

Reputation: 719

Question is not cleared. I think you want to concat price range with this query. Please try with it and let me know. If your price is an integer then remove the quote from the digit.

SELECT id,tableid,category,price,actualprice,image,title,website,description 
FROM tt_1 
where 
       title like 'Home Appliances%' or 
       image like 'Home Appliances%' or 
       category like 'Home Appliances%' or 
       site_master_url like 'Home Appliances%' or 
       website like 'Home Appliances%' AND 
       price between 'STARTING_RANGE' AND 'ENDING_RANGE'

Upvotes: 0

rjv
rjv

Reputation: 6766

Question unclear.
I believe this is what you want.To specify a range in mysql use BETWEEN

SELECT * FROM table WHERE price BETWEEN lower AND upper;

Upvotes: 2

Related Questions