我有两张表country
和state
:
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不接受'+'符号吗?
答案 0 :(得分: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
答案 1 :(得分:0)
试试这个::
select
s.sid,
s.statename,
c.countryName
from country c
LEFT JOIN state s on s.cid = c.cid
WHERE c.id=1
答案 2 :(得分:0)
删除加号和。符号...
Select s.sid,s.statename,c.countryName from state s,
left join country c on s.cid = c.cid where c.id=1
答案 3 :(得分:0)
SELECT s.sid,
s.statename,
c.countryname
FROM country c
LEFT JOIN state s on (s.cid = c.cid )
where c.cid = 1;