1

我有两张桌子countrystate

country
-----------
cid
countrycode
countryname

state
-------
sid
cid (fk)
statecode
statename

我正在写一个联接:

SELECT s.sid, 
       s.statename, 
       c.countryname 
FROM   state s, 
       country c 
WHERE  s.cid = (+) c.cid 
       AND c.id = 1 

上面的查询给出了一个语法错误。MySQL不接受'+'符号吗?

4

4 回答 4

3

不,MySQL 不接受该+符号。除了少数例外,MySQL 使用 ANSI 标准JOIN语法:

SELECT s.sid, 
       s.statename, 
       c.countryname 
FROM   state s 
       LEFT JOIN country c 
              ON c.id = s.cid 
WHERE  c.id = 1 
于 2013-10-08T13:15:22.363 回答
0

尝试这个::

select 
s.sid,
s.statename,
c.countryName 
from country c 
LEFT JOIN state s on  s.cid = c.cid 
WHERE c.id=1
于 2013-10-08T12:54:35.010 回答
0

删除加号查询末尾的符号...

Select s.sid,s.statename,c.countryName from state s,
left join country c on s.cid = c.cid where c.id=1
于 2013-10-08T12:56:05.577 回答
0

这会帮助你。

 SELECT s.sid, 
       s.statename, 
       c.countryname 
FROM   country c 
LEFT JOIN state s on (s.cid = c.cid )
where c.cid = 1;
于 2013-10-08T13:03:59.333 回答