Reputation: 377
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
Upvotes: 0
Views: 233
Reputation: 958
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'
Upvotes: 1
Reputation: 359
$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.
Upvotes: 0
Reputation: 10103
SELECT * FROM tbl
WHERE (specification='%value1%' OR specification='%value2%')
group by propertyCode
Upvotes: 0
Reputation: 263883
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
Upvotes: 0