-- 数据库sql_store中表order_items 连接 数据库sql_inventory中表products
-- O表内连接P表,条件为(即ON为)O表和P表的product_id相等,注:两个表中都出现的列名前需加表名指定
-- 需要给不在当前数据库的表加前缀,根据当前使用的数据库的变化而变化
USE sql_store;
SELECT *
FROM order_items AS O
JOIN sql_inventory.products AS P
ON O.product_id = P.product_id;
运行结果: