mysql - How canI join a table with itself for a query in a PHP script, and tell the script which column to pick from which table?
552
Solution:
You actually have table aliases (c and cc). So you need aliases for your attributes. I mean something like this:
$sql = "SELECT DISTINCT c.co_name as nameA, cc.co_name as nameB
FROM Deliveries d
INNER JOIN Companies c ON d.id_co = c.id_co,
Deliveries dd
INNER JOIN Companies cc ON dd.id_co = cc.id_co
WHERE d.id_obj = dd.id_obj
AND d.id_sup = dd.id_sup
AND d.id_co < dd.id_co";
Later use your echo line like this:
echo "<tr><td>".$row["nameA"]."</td><td>".$row["nameB"]."</td></tr>";
Hope it helps you...