Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL Joining to Same Table with Multiple ON Conditions?
    primarykey
    data
    text
    <p>Still a mysql newb and I looked extensively through previous questions trying to find an appropriate solution.</p> <p>I have two tables <code>CaseReportsTempImport2011Q3</code> and <code>FDADrugsDB</code>, I want to do a left join to match <code>CaseReportsTempImport2011Q3.drugname</code> to <code>FDADrugsDB.ReferenceDrugName</code> and <code>FDADrugsDB.DrugName</code> </p> <p>What I envisioned was something like:</p> <pre><code>SELECT DISTINCT(CaseReportsTempImport2011Q3.DRUGNAME) , FDADrugsDB_Product.drugname , FDADrugsDB_Product.ReferenceDrug , FDADrugsDB_Product.activeingred FROM CaseReportsTempImport2011Q3 LEFT JOIN FDADrugsDB_Product ON CaseReportsTempImport2011Q3.DRUGNAME LIKE TRIM(FDADrugsDB_Product.ReferenceDrug) LEFT JOIN FDADrugsDB_Product ON CaseReportsTempImport2011Q3.DRUGNAME LIKE TRIM(FDADrugsDB_Product.DrugName) ORDER BY LENGTH(CaseReportsTempImport2011Q3.DRUGNAME) ASC </code></pre> <p>But that doesn't work I get 'Not unique table/alias: 'FDADrugsDB_Product'' - Any help?</p> <p>Thanks</p> <p><strong>EDIT FOR BETTER SOLUTION REQUEST/REPHRASE</strong> Per borealids "However, I'm not sure this is what you want to do - joining the table twice will produce a multiplicative number of results. I think you might have wanted one join with an ON ... OR ..., making the join condition an "or" of the two reasons for linkage."</p> <p>I would like to know how to do that.</p> <p><strong>SOLUTION</strong> ON CaseReportsTempImport2011Q3.DRUGNAME LIKE TRIM(FDADrugsDB_Product.ReferenceDrug) OR CaseReportsTempImport2011Q3.DRUGNAME LIKE TRIM(FDADrugsDB_Product.DrugName</p> <p>Thanks tom and borealid.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload