• [^] # Re: NOT EXISTS

    Posté par . En réponse au message mysql et requetes imbriques. Évalué à 1.

    Et ca, ca ne marcherait pas ???

    SELECT Produit.Prod_Nom FROM Produit, SocieteProd WHERE Produit.Prod_ID= SocieteProd.Produit_ID and SocieteProd <> "$societe_id"

    A priori, ca prend bien tous les produits, sauf ceux que fait la société, non ?
    Enfin, ceci dit, la version stable 4.1 vient de sortir, ca serait dommage de s'en priver :)

    Sinon, dans le même genre, il y a ca dans la doc MySQL :

    Sometimes you want to retrieve the records that DONT match a select statement.

    Consider this select:
    SELECT CarIndex FROM DealerCatalog, BigCatalog WHERE
    DealerCatalog.CarIndex=BigCatalog.CarIndex

    This finds all the CarIndex values in the Dealer's catalog that are in the bigger distributor catalog.


    How do I then find the dealer CarIndex values that ARE NOT in the bigger catalog?

    The answer is to use LEFT JOIN - anything that doesn't join is given a NULL value , so we look for that:

    SELECT CarIndex FROM DealerCatalog LEFT JOIN BigCatalog ON DealerCatalog.CarIndex=BigCatalog.CarIndex WHERE BigCatalog.CarIndex IS NULL

    http://dev.mysql.com/doc/mysql/fr/SELECT.html(...)