mysql查询问题内连接

时间:2011-08-17 16:55:11

标签: mysql

我是否可以执行此查询,如果不能,我该如何将其更改为

SELECT
    clientinfo.clientname, clientinfo.clientcode, clientinfo.serverid,
    serverslist.servername
FROM clientinfo 
where clientinfo.clientjurisdiction='$groupid' && clientinfo.clientcode REGEXP '$expression' 

INNER JOIN 
serverslist ON clientinfo.serverid=serverslist.serverid 
ORDER BY clientinfo.clientcode 

4 个答案:

答案 0 :(得分:2)

您必须将INNER JOIN移动到FROM子句中,如下所示:

SELECT c.clientname, c.clientcode, c.serverid, s.servername 
FROM clientinfo c INNER JOIN serverslist s ON c.serverid=s.serverid
WHERE c.clientjurisdiction='$groupid' && c.clientcode REGEXP '$expression' 
ORDER BY c.clientcode 

答案 1 :(得分:1)

订单应该是

SELECT ...
FROM ... INNER JOIN ... ON ...
WHERE ...
ORDER BY ...

答案 2 :(得分:0)

SELECT
clientinfo.clientname, clientinfo.clientcode, clientinfo.serverid,
serverslist.servername
FROM clientinfo, serverslist 
where clientinfo.clientjurisdiction='$groupid' AND clientinfo.clientcode REGEXP    '$expression' AND 
serverslist ON clientinfo.serverid=serverslist.serverid 
ORDER BY clientinfo.clientcode 

答案 3 :(得分:0)

join子句应放在from和where子句之间。

此外,您可以使用表别名来使查询更易于阅读。例如

SELECT
    c.clientname, c.clientcode, c.serverid, s.servername
FROM clientinfo c
    INNER JOIN serverslist s ON c.serverid = s.serverid 
WHERE c.clientjurisdiction = '$groupid' AND c.clientcode REGEXP '$expression' 
ORDER BY c.clientcode