使用 Medoo 连接表格 (MySQL)
Joining tables with Medoo (MySQL)
我对数据库不太熟悉,我 运行 遇到了必须使用 join
.
的情况
products
table:
╔════════════╦═════════╦═════════════════╗
║ product_id ║ MPN ║ manufacturer_id ║
╠════════════╬═════════╬═════════════════╣
║ 51 ║ GB40337 ║ 11 ║
╚════════════╩═════════╩═════════════════╝
manufacturers
table:
╔═════════════════╦═════════╗
║ manufacturer_id ║ name ║
╠═════════════════╬═════════╣
║ 11 ║ Griffin ║
╚═════════════════╩═════════╝
据我了解,需要内部联接才能获取制造商名称?所以我 运行 这个查询:
SELECT product.mpn, manufacturer.name
FROM product
INNER JOIN manufacturer
ON product.manufacturer_id=manufacturer.manufacturer_id;
它 returns 数据正确,但现在因为我正在使用 Medoo
我必须使用它的语法,我不太明白:http://medoo.in/api/select
如何使用 medoo 进行相同的查询?
试试这个
$database->select("product", [
"[><]manufacturer" => ["manufacturer_id" => "manufacturer_id"]], [
"product.mpn",
"manufacturer.name"]);
在 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')
);
我对数据库不太熟悉,我 运行 遇到了必须使用 join
.
products
table:
╔════════════╦═════════╦═════════════════╗
║ product_id ║ MPN ║ manufacturer_id ║
╠════════════╬═════════╬═════════════════╣
║ 51 ║ GB40337 ║ 11 ║
╚════════════╩═════════╩═════════════════╝
manufacturers
table:
╔═════════════════╦═════════╗
║ manufacturer_id ║ name ║
╠═════════════════╬═════════╣
║ 11 ║ Griffin ║
╚═════════════════╩═════════╝
据我了解,需要内部联接才能获取制造商名称?所以我 运行 这个查询:
SELECT product.mpn, manufacturer.name
FROM product
INNER JOIN manufacturer
ON product.manufacturer_id=manufacturer.manufacturer_id;
它 returns 数据正确,但现在因为我正在使用 Medoo
我必须使用它的语法,我不太明白:http://medoo.in/api/select
如何使用 medoo 进行相同的查询?
试试这个
$database->select("product", [
"[><]manufacturer" => ["manufacturer_id" => "manufacturer_id"]], [
"product.mpn",
"manufacturer.name"]);
在 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')
);