3

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?

eozzy
  • 66,048
  • 104
  • 272
  • 428
  • Did you try `// [><] == INNER JOIN` as described in the "Table Joining" part of the page you referred to? – Alex Blex Oct 04 '16 at 11:56

2 Answers2

2

try this

$database->select("product", [
            "[><]manufacturer" => ["manufacturer_id" => "manufacturer_id"]], [
            "product.mpn",
            "manufacturer.name"]);
Rakesh Sojitra
  • 3,538
  • 2
  • 17
  • 34
2

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')
);
eozzy
  • 66,048
  • 104
  • 272
  • 428