0

Eddited to more accurate problem:
i have a table: id, supplierCode, propertyCode, specification. While doing search in products i would like to get products that specifications has a text like value1 and value2, so to get those products i would like an query sumething like this:
SELECT * FROM tbl WHERE (specification LIKE '%value1%' OR specification LIKE '%value2%') AND (those 2 got rows has the same supplierCode)
Or from other side of problem: Get all supplierCode's where whatever rows with same supplierCode has in the specification columns LIKE '%value1%' AND LIKE '%value2%'
Example:
id supplierCode propertyCode, specification
1 001234 11 i7-blabla
2 001234 13 15.3"
3 004321 15 i7-9761
4 004321 16 15.4"
5 003214 14 i7-15.3"

And if i'm searching for 'i7' and '15.3"' i could get 001234 and 003214 becouse they has i7 and 15.3" in their specifications

2
  • try googling for LIKE operator Commented Aug 6, 2012 at 22:47
  • you only need the % when you are using LIKE, not when you are using =. An IN statement would already be a better choice then using the OR operator Commented Aug 6, 2012 at 22:49

5 Answers 5

1

You can use the IN clause--definitely research thi problem a bit more, you would've definitely found a solution somewhere in the web.

    SELECT * FROM tbl 
    WHERE specification IN ('value1', 'value2')
      AND propertyCode = 'SOME_VALUE'
Sign up to request clarification or add additional context in comments.

1 Comment

ups, srry, i meant 'LIKE' not '='
0

use LIKE instead of = sign

SELECT * 
FROM tbl 
WHERE (
       specification LIKE CONCAT('%', value1, '%') OR 
       specification LIKE CONCAT('%', value2, '%') 
      ) AND 
      propertyCode = valueHere

but if you are sure with the specification values use IN instead of OR (actually they are the same)

SELECT * 
FROM tbl 
WHERE  specification IN ('value1','value2') AND 
       propertyCode = valueHere

1 Comment

his problem is "AND (has the same propertyCode)"
0

you can use like keyword

pattern matching

Comments

0
 SELECT * FROM tbl 
 WHERE (specification='%value1%' OR specification='%value2%') 
 group by propertyCode     

Comments

0
$find = mysql_query("SELECT * FROM `tbl` WHERE (`specification` LIKE '%$value1%' OR `specification` LIKE '%$value2%') AND `propertyCode`='$propertycode'")or die(mysql_error());
$display = mysql_fetch_array($find);

Bare in mind you will need to change the PHP variables as you have not included any I have to presume you are looking for something like the above.

Also if you are looking to create a list then you will need to use a while statement on your fetch.

Comments

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.