我有 2 个数据库和 2 个表
Database 1 has table : Product
Database 2 has table : stock
产品具有以下行
product_ID, product_code....etc
库存有
Product_code, stock_on_hand
我需要在用户插入product_ID时获取库存量,请帮忙
最佳答案
您只需JOIN
两个表即可。由于表托管在不同的数据库上,因此您需要在表名前添加数据库名称前缀。
查询:
SELECT s.stock_on_hand
FROM db2.stock s
INNER JOIN db1.product p
ON s.product_code = p.product_code
AND p.product_id = ?
您可以将问号替换为用户正在搜索的product_id
。
关于php - SQL 从 2 个不同的数据库检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58197219/