我对数据库不太熟悉,而且我遇到了必须使用join
的情况。
products
表:
╔════════════╦═════════╦═════════════════╗
║ product_id ║ MPN ║ manufacturer_id ║
╠════════════╬═════════╬═════════════════╣
║ 51 ║ GB40337 ║ 11 ║
╚════════════╩═════════╩═════════════════╝
manufacturers
表:
╔═════════════════╦═════════╗
║ manufacturer_id ║ name ║
╠═════════════════╬═════════╣
║ 11 ║ Griffin ║
╚═════════════════╩═════════╝
据我了解,需要内部联接才能获得制造商名称?所以我运行了这个查询:
SELECT product.mpn, manufacturer.name
FROM product
INNER JOIN manufacturer
ON product.manufacturer_id=manufacturer.manufacturer_id;
并且它正确地返回数据但是现在因为我使用Medoo
我必须使用它的语法,我无法得到:http://medoo.in/api/select
如何对同一查询使用medoo?
答案 0 :(得分:2)
在Medoo中您可以像这样编写查询。
阅读此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')
);
答案 1 :(得分:0)
试试这个
$database->select("product", [
"[><]manufacturer" => ["manufacturer_id" => "manufacturer_id"]], [
"product.mpn",
"manufacturer.name"]);