phpmysqlmedoo

Joining tables with Medoo (MySQL)


I'm not too familiar with databases and I've run into a situation where I have to use a join.

products table:

╔════════════╦═════════╦═════════════════╗
║ product_id ║   MPN   ║ manufacturer_id ║
╠════════════╬═════════╬═════════════════╣
║         51 ║ GB40337 ║              11 ║
╚════════════╩═════════╩═════════════════╝

manufacturers table:

╔═════════════════╦═════════╗
║ manufacturer_id ║  name   ║
╠═════════════════╬═════════╣
║              11 ║ Griffin ║
╚═════════════════╩═════════╝

Now as I understand, it would require an inner join to get the manufacturer name? So I ran this query:

SELECT product.mpn, manufacturer.name
FROM product
INNER JOIN manufacturer
ON product.manufacturer_id=manufacturer.manufacturer_id;

and it returns the data correctly but now since I'm using Medoo I have to use its syntax which I can't quite get: http://medoo.in/api/select

How do I use medoo for the same query?


Solution

  • In Medoo You can write your query like this.

    read this https://www.sitepoint.com/getting-started-medoo-examples-use/

    $db->select(
        'product', 
        array('[><]manufacturer' => array('product.manufacturer_id' => 'manufacturer.manufacturer_id')),
        array('product.mpn', 'manufacturer.name')
    );