sql >> Database teknologi >  >> RDS >> Mysql

Forespørgsel returnerer ikke resultater som forventet

Dette bør sikre, at det har begge dele.

WHERE   id IN 
        ( 
        SELECT  clientid 
        FROM    campaigns 
        WHERE   status IN ('L') 
        ) 
    AND id  IN 
        ( 
        SELECT  clientid 
        FROM    campaigns 
        WHERE   status IN ('P') 
        ) 

Eller prøv endda Underforespørgsler med EXISTS

WHERE   EXISTS
        (
        SELECT  clientid 
        FROM    campaigns 
        WHERE   status IN ('L') 
        AND     clientid = client.id
        )    
    AND EXISTS
        (
        SELECT  clientid 
        FROM    campaigns 
        WHERE   status IN ('P') 
        AND     clientid = client.id
        ) 


  1. Sådan GRUPPERES BY en streng-del i MySQL

  2. Dynamisk forespørgsel i MySQL

  3. Sådan benchmarker du Moodles ydeevne

  4. Forespørgsel med flere likes