Hello! Dear, help make this condition in ('AUDI' and 'FIAT') . I understand perfectly well that it is impossible to do this syntactically, but who can know how to construct such a condition. Those. in fact, I want to make sure that in the IN clause only these two values ​​of 'AUDI' and 'FIAT' are selected

Amendment. This is what I need:

Table with values:

ID_USER | VALUE ---------------- 1 | AUDI 2 | FIAT 2 | AUDI 3 | FIAT 

It is necessary that the condition would be displayed 2 users who have this and that value

    5 answers 5

    Request

     SELECT `car`.`ID_USER` FROM `car` , ( SELECT `ID_USER` FROM `car` WHERE `VALUE` = 'AUDI' ) AS t1 WHERE `car`.`VALUE` = 'FIAT' AND t1.ID_USER = `car`.`ID_USER` 

    one more

     SELECT `car`.`ID_USER` FROM `car` WHERE `car`.`VALUE`='FIAT' and `car`.`ID_USER` in (SELECT `ID_USER` FROM `car` WHERE `VALUE`='AUDI') 
       select ID_USER from table where VALUE in ('AUDI', 'FIAT') group by ID_USER having count(*) = 2; 

      And if one user with one brand can appear several times, then this:

       select ID_USER from table where VALUE in ('AUDI', 'FIAT') group by ID_USER having count(distinct VALUE) = 2; 
         select * from table where car in ('AUDI', 'FIAT'); 

        or

         select * from table where car='AUDI' or car='FIAT'; 
        • it is necessary for me that two values ​​from the condition, i.e. if the field does not meet the condition of AUDI and FIAT then this field does not fit into the sample ... it seems that it should be clear ... why I don’t explain clearly - Artyomich

        Here is the answer.

        But I will offer my own version:

         select ID_USER from table t where exists (select * from table t1 where t1.ID_USER = t.ID_User and Value = 'AUDI') and exists (select * from table t1 where t1.ID_USER = t.ID_User and Value = 'FIAT') 
        • In! I would write like that too! - orkaan
         select * from `table` where `car` like('%AUDI%') and `car` like('%FIAT%'); 

        It will look for the field to contain both of these words. If the words are only two, you can replace

         select * from `table` where `car` = ('AUDI,FIAT') OR `car`=('FIAT,AUDI'); 

        UPD. the third normal form is quite capable of helping to cope with this task. To do this, create a table with stamps, index everything once, and then make a request for compliance. It is possible through your favorite IN. :)