product
table:
╔══════════════════════════════════╦═══════════╦═══════════════════╦════════════════════╦════╗
║ ref ║ mfr ║ pnum ║ ssku ║ id ║
╠══════════════════════════════════╬═══════════╬═══════════════════╬════════════════════╬════╣
║ 6541_aten_2a-130g ║ Aten ║ 2A-130G ║ 2A-130G ║ 6 ║
║ 7466_eaton_5sc1000i ║ Eaton ║ 5SC1000I ║ ║ 8 ║
║ 8214_ivanti-uk_template-material ║ IVANTI UK ║ TEMPLATE MATERIAL ║ 000000000003616655 ║ 4 ║
║ 8361_aywun_92sfan1 ║ Aywun ║ 92SFAN1 ║ 92SFAN ║ 9 ║
║ 9824_autodesk_00100-000000-9880 ║ AUTODESK ║ 00100-000000-9880 ║ 00100-000000-9880 ║ 5 ║
╚══════════════════════════════════╩═══════════╩═══════════════════╩════════════════════╩════╝
inventory
table:
╔══════════════════════════════════╦═══════╦═════════╦═════════════════════╗
║ ref ║ scost ║ instock ║ date ║
╠══════════════════════════════════╬═══════╬═════════╬═════════════════════╣
║ 6541_aten_2a-130g ║ 26 ║ 0 ║ 2017-05-27 10:45:23 ║
║ 7466_eaton_5sc1000i ║ 489 ║ 0 ║ 2017-05-27 10:45:23 ║
║ 8214_ivanti-uk_template-material ║ 0 ║ 0 ║ 2017-05-27 10:45:23 ║
║ 8361_aywun_92sfan1 ║ 4 ║ 0 ║ 2017-05-27 10:45:23 ║
║ 9824_autodesk_00100-000000-9880 ║ 738 ║ 0 ║ 2017-05-27 10:45:23 ║
╚══════════════════════════════════╩═══════╩═════════╩═════════════════════╝
... and I'm looking to do a FULL OUTER JOIN
(get columns from both tables only if key exists in both if I understand correctly?) using Medoo:
$data = $database->select("product", [
"[<>]inventory" => ["ref" => "ref"],
]);
Error:
Invalid argument supplied for foreach() in /var/www/html/vendor/catfan/medoo/src/Medoo.php on line
I also tried these queries in the console but getting a syntax error:
SELECT *
FROM product
FULL OUTER JOIN product ON product.ref = inventory.ref;
and
SELECT * FROM `product`, * FROM `inventory`
WHERE product.`ref` = inventory.`ref`;
Expected result:
╔═══════════════════╦══════╦═════════╦═════════╦════╦═══════╦═════════╦═════════════════════╗
║ ref ║ mfr ║ pnum ║ ssku ║ id ║ scost ║ instock ║ date ║
╠═══════════════════╬══════╬═════════╬═════════╬════╬═══════╬═════════╬═════════════════════╣
║ 6541_aten_2a-130g ║ Aten ║ 2A-130G ║ 2A-130G ║ 6 ║ 26 ║ 0 ║ 2017-05-27 10:45:23 ║
╚═══════════════════╩══════╩═════════╩═════════╩════╩═══════╩═════════╩═════════════════════╝
Mysql does not support
FULL OUTER JOIN
, and your logic seems to beINNER JOIN
:But I don't know why in two tables the
ref
's are all the same, your expected result only have one record, and according to Medoo document, the code should be like following:For all of your tables, try this: