什么是正确的JOIN语法?

时间:2012-08-26 09:41:01

标签: php mysql join multiple-tables multiple-databases

我的'服务器'位于不同的数据库中,我需要从所有数据库中提取一些数据。每个server数据库都有一个uz_general表,其中包含idownername列字段。

我的查询目的是计算用户在所有服务器中拥有的条目数。问题是,在我发现的每个JOIN教程中,您还需要指定表名,并且我正在尝试创建一个不必在添加或添加新服务器时更改的代码一些被删除。到目前为止,我已尝试在没有JOINS的情况下做出替代方案,但是,我确实感觉它远远不够好,此外,它无法正常工作,因为WHERE可能希望每个表名都指定为好。

$get_serv=$db->get('SELECT * FROM `serverlist` ORDER BY `recco`,`premium` DESC',1800); //Getting the list of servers appropriate to the user's selected language
foreach ($get_serv as $k) $servers.='`server_'.$k['name'].'`.`uz_general`,'; //Making the little string for the query's FROM
$numC=$db->count('SELECT count(*) FROM '.substr($servers,0,-1).' WHERE `owner`='.$_SESSION['acc'].' LIMIT 5',0,0); // counts the occurrences from the fetched server names WHERE the owner ID is the same as the logged in user's ID.

我应该为每个WHERE执行相同的程序,还是有更好的方法来执行此操作?再次,我尝试将其转换为JOIN,但简单无法找到方法。

0 个答案:

没有答案