MYSQL-从不同的数据库中选择 [英] MYSQL - SELECT from different databases
本文介绍了MYSQL-从不同的数据库中选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在同一查询中将数据从两个不同的数据库中选择到同一服务器中? 这是我正在做的,但是我的查询不起作用:
How can I select data in the same query from two different databases into the same server? This is what I'm doing, but my query doesn't works:
$sqlquery = "SELECT * FROM database_2.table_2 WHERE database_1.table_1.data_1 LIKE database_2.table_2.data_2";
$result = mysql_query($sqlquery);
$number = mysql_numrows($result);
$i = 0;
if ($number < 1) {
print "DOH";
}else{
while ($number > $i) {
$content = mysql_result($result,$i,"database_2.table_2.data_3");
print "$content";
$i++;
}
}
推荐答案
问题不在于其他数据库.
The problem is not about different databases.
您的WHERE子句引用FROM子句中未提供的字段database_1.table_1.data_1.
Your WHERE clause references the field database_1.table_1.data_1 which was not supplied in the FROM clause.
你不是说类似的东西
SELECT *
FROM database_2.table_2
JOIN database_1.table_1
ON (database_2.table_2.some_field = database_1.table_1.some_other_field)
WHERE database_1.table_1.data_1 LIKE database_2.table_2.data_2
?
还
echo mysql_error();
查询失败后-这将为您提供有关出问题的线索.
after your failed query - this will give you a clue about what's wrong.
这篇关于MYSQL-从不同的数据库中选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文