SQL/MySQL - How to implement AND clause in one-to-many relationship? -
I'm sure this is a common problem, but I am unable to think about an answer.
If I have a table with one-to-one relationship, how can I apply a query where to return the record, all the specified items from the "many" sides of the relationship To complete?
For example
person person Feature Feature Person Identity Name Personality Feature ID Feature ID Description 1 Dave 1 1 1 Long 2 Bill 1 2 2 Black 1 3 3 Male 2 1 4 White 2 4 2 3 If I was allowing the user to choose from the features in the Feature table, how would I write a query that can only return to the person whose facility is All was selected, though some or many of them are Awareness is?Then will not return Dave back in search of a tall, black, man, but the search for both of the tall men will return.
This should do one thing:
SELECT P.Name person From Person P JOIN Person_F APFCID PF P. Pscdid = pf Percondid Feature F on PF. Factor ID = F. Fitteroid Where F. Description in ('Long', 'Black') Group P. PST is being done by PSCNID (*) = 2
Actually, I am selecting all those people who have the search criteria given by the ID and the people of the group. Then I filter them by COUNT. If there are 2 criteria, it means that there must be 2 rows (if 3 are, then
COUNT (*) should be 3) If the calculation is less than the number of criteria, it means that That person does not match all norms (but only a few).
Comments
Post a Comment