MySQL:在两个数据库

时间:2017-06-27 08:37:57

标签: mysql magento

我正在尝试从两个数据库中获取数据(它们位于同一台服务器上)。我想要的是从数据库2获取数据库的数据库1.我正在努力加入JOIN。我想匹配ean(d.value),因为这个确实存在于第二个数据库中。

SELECT 
    a.sku AS sku, 
    c.value AS name, 
    d.value AS ean,
    e.value AS price,
    f.n_factuurprijs AS tech_price
FROM 
    catalog_product_entity a, 
    catalog_product_entity_int b, 
    catalog_product_entity_varchar c, 
    catalog_product_entity_varchar d,
    catalog_product_entity_decimal e
JOIN
    product_stock_price.techdata_products f ON f.ean = ean
WHERE 
    a.entity_id = b.entity_id
    AND a.entity_id = c.entity_id
    AND a.entity_id = d.entity_id
    AND a.entity_id = e.entity_id
    AND d.attribute_id = f.ean
    AND b.attribute_id = 96
    AND b.value = 1
    AND c.attribute_id = 71
    AND d.attribute_id = 152
    AND e.attribute_id = 75 
GROUP BY a.entity_id

正如您所看到的,我对MySQL很新。所以任何帮助都非常感谢。

1 个答案:

答案 0 :(得分:0)

您可以使用语法databasename.tablename指定数据库 e.g。

SELECT 
    db1.user_table.id, 
    db2.user_table.id
FROM 
   db1.user_table
       INNER JOIN db2.user_table 
           ON db1.user_table.id = db2.user_table.id