小弟我在mysql里开发,写了这么个sql语句,提示不对:SELECT `ResourceId` , `Title` , `Description` , `URL` FROM `Resources` WHERE 'ResourceId' IN ( SELECT URLid FROM URLStat WHERE Stat = 404 )系统错误提示如下
MySQL said: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT URLid FROM URLStat WHERE Stat = 404 ) LIMIT 0, 30' at li字段名都没错;404改为'404'也不行;请问是怎么回事,谢谢!
MySQL said: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT URLid FROM URLStat WHERE Stat = 404 ) LIMIT 0, 30' at li字段名都没错;404改为'404'也不行;请问是怎么回事,谢谢!
SELECT `ResourceId` , `Title` , `Description` , `URL` FROM `Resources`
WHERE 'ResourceId' IN(SELECT URLid FROM URLStat WHERE Stat = 404 )
自己又改成下面这样,也不行!
SELECT t1.ResourceId, t1.Title, t1.Description, t1.URL FROM `Resources` AS t1 WHERE t1.ResourceId IN ( SELECT t2.URLid FROM URLStat AS t2 WHERE t2.Stat = 404 )
[/align]
FROM `Resources` AS t1
WHERE exists( SELECT t2.URLid FROM URLStat AS t2 WHERE t2.Stat = 404 and URLid=t1. ResourceId)[align=center]==== 思想重于技巧 ====
[/align]
left join URLStat AS t2 on t1.ResourceId=t2.URLid
WHERE t2.Stat = 404 and t2.URLid is not null
orSELECT t1.ResourceId, t1.Title, t1.Description, t1.URL FROM `Resources` AS t1
inner join URLStat AS t2 on t1.ResourceId=t2.URLid
WHERE t2.Stat = 404
[/align]
SELECT t1.ResourceId, t1.Title, t1.Description, t1.URL FROM `Resources` AS t1 inner join URLStat AS t2 on (t1.ResourceId = t2.URLid and t2.Stat = 404 )