SORRY I COULDN'T THINK OF BETTER TITLE
usually we have a table
and we have a query
and we want rows which in them
query = table
but what if also want the rows if query > table
so here is an example , lets say we have a website which connects people who wants some services to companies , we have 4 services a,b,c,d,
so a user would select his desired services an we store them in database
wanted :
+-----------+----------+---------+------+--------
| user_id | a | b | c | d |
+-----------+----------+---------+------+--------
| 23 | 1 | 0 | 1 | 0 |
+-----------+----------+---------+---------------
for example this guy wants a,c
now a company would come to our website and says we offer a,c
so i query
$query = "select user_id from wanted where a=1 && c =1 ";
i get user 21 and i would connect them to each other .
but what if the company offers services a,b,c
$query = "select user_id from wanted where a=1 && b =1 && c=1 ";
it wouldn't return user 21 , but it should .... they are not perfect match but service required by user 21 is covered by this company
i know i should to the process other way around and first store companies and let the users search for them and i wouldn't have this problem , but this how this website works
so what are my options ? anything can be done ?
pleas note that i can't use OR ||
cuz the company should cover all the needs of customer so if i have a user x
which wants a,b,c
and company with a,b,d
the query
select * from wanted where a = 1 || b = 1 || d = 1
would return user x
and thats wrong cuz the company doesn't cover desired service c
I would use OR to get all users which are at least in one service:
$query = "select user_id from wanted where a = 1 OR b = 1 OR c = 1 ";
Almost seems like too simple of a fix, but how about OR instead of AND?
$query = "select user_id from wanted where a=1 or b =1 or c=1 ";
In your senario you could use or rather than and so
where a=1 || b =1 || c=1 ";
which would return any customer who wants product a, b or c bit not necessarily all of them.
Personally I would change the structure of the database so I had a products table and a customers tables then a 1 to many join between the two tables. That would allow you to query like:
where product.product_id IN (1,2,3);