MySQL is not my fad, so I didn’t even know how to write the title of the post correctly ... In general, the point is this. For example, there is one table with two fields F1 and F2

alt text

We search in the field F2 , we get DISTINCT F1 . If the parameter is one, for example A , then we get three entries at the output: 7 , 12 , 5 . But if there are two parameters A and B , then how to make a request to pull out only two records 7 and 5 . We eliminate 12 , because does not have parameter B in it? So, as I build a query - this can not naturally be achieved.

SELECT DISTINCT F1 FROM table WHERE F2 IN ('A','B') 

    2 answers 2

     SELECT t1.F1 FROM `table` t1 JOIN (SELECT tt2.F1 FROM `table` tt2 WHERE tt2.F2='B') t2 ON t1.F1 = t2.F1 WHERE t1.F2='A'; 
    • Oh thank you. Saved me from my sleepless night)) - Deonis

    I understand it is necessary to get the values ​​of f1 which have all the values ​​of f2 (A, B, C), the request will be of the following form:

     SELECT DISCTINCT f1, f2, count(*) as cnt from tbl group by f1, f2 having cnt = 3; 
    • Thank. Very close, but a bit wrong. In general, @Yura Ivanov gave a completely satisfying solution. - Deonis