万网租的空间,数据库是mysql4.0。
查询语句如下:
SELECT
NoticeID,
(select UserName from Zcml_User where UserID=Zcml_Notice.NoticeAud)NoticeAud
from Zcml_Notice
where NoticeType='0'
order by NoticeStatus,NoticeAddDate DESC
提示错误:
1064-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 UserName from Zcml_User where UserID=Zcml_Notice.NoticeA
请高手帮忙解决。谢谢!
查询语句如下:
SELECT
NoticeID,
(select UserName from Zcml_User where UserID=Zcml_Notice.NoticeAud)NoticeAud
from Zcml_Notice
where NoticeType='0'
order by NoticeStatus,NoticeAddDate DESC
提示错误:
1064-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 UserName from Zcml_User where UserID=Zcml_Notice.NoticeA
请高手帮忙解决。谢谢!
NoticeID,
(select UserName from Zcml_User where UserID=Zcml_Notice.NoticeAud)NoticeAud
from Zcml_Notice
where NoticeType='0'
order by NoticeStatus,NoticeAddDate DESC
from Zcml_Notice a ,Zcml_User b
where a.NoticeAud=b.UserID
and a.NoticeType='0'
order by a.NoticeStatus,a.NoticeAddDate DESC
参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
1. 你的 create table xxx .. 语句
2. 你的 insert into xxx ... 语句
3. 结果是什么样,(并给以简单的算法描述)
4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。
from Zcml_Notice a left join Zcml_User b on a.NoticeAud=b.UserID
where a.NoticeType='0'
order by a.NoticeStatus,a.NoticeAddDate DESC
UserID UserName
admin 管理员
aa 用户1
bb 用户2
cc 用户3表Zcml_Notice
NoticeID NoticeTitle NoticeAud
01 标题1 aa
02 标题2 aa
03 标题3 cc
04 标题4 bb想要如下的查询结果:
01 标题1 用户1
from Zcml_Notice a,Zcml_User b
where a.NoticeAud=b.UserID
谢谢!!
select a.NoticeID,a.NoticeTitle,b.UserName
from Zcml_Notice a,Zcml_User b
where a.NoticeAud=b.UserID or a.NoticeAud is null;
from Zcml_Notice a left join Zcml_User b on a.NoticeAud=b.UserID