Selecting where not

    Date: 01/23/06 (MySQL Communtiy)    Keywords: no keywords

    I have two tables

    drugs

    drug_id | category_id | drug_name | information | warnings


    qty_price

    id | drug_id | pharmacy_id | cost | generic | strength


    I want to get a list of drug names where the drug is not listed in qty_price.

    SELECT drugs.drug_name
    FROM drugs, qty_price
    WHERE drugs.drug_id != qty_price.drug_id
    ORDER BY drug_name ASC
    LIMIT 50

    This seems incredibly inefficient. It has to search every row in drugs for every id in qty_price, I think.
    There has to be a better way, but I dont see it because my brain went to bed without me.

    Anyone have a resource or answer?
    Any help is much appreciated.

    Source: http://community.livejournal.com/mysql/83931.html

« Update multiple tables || message structure advice »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home