如何把两个甚至更多的表关联起来??

ecobin 2004-04-19 10:06:46
比如, 帖子内容放在Topic表,其中有这么几个字段ID | content(帖子内容) | ........ | PostUserName(发帖人)
另外的,另外的一个表User,纪录了用户的资料,有ID | Email | Homepage

请问,如何在显示帖子内容的同时。也显示出PostUser的主页、EMAIL呢?

是不是用SQL的JOIN呢?
还请大虾详细用自己的语言的解释一下JOIN
...全文
70 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
loveweb 2004-04-19
  • 打赏
  • 举报
回复
select T.ID,T..content,P.PostUserName,U.email ,U.Homepage
from Topic T left join User U on T.PostUserName = U.UserName
skyboy0720 2004-04-19
  • 打赏
  • 举报
回复
select topic.id,topic.content,user.username,user,email from Topic where PostUserName in ( select username from User )

或者

select topic.id,topic.content,user.username,user,email inner Topic join User
on topic.PostUserName=User.username
787912 2004-04-19
  • 打赏
  • 举报
回复
"select topic.id,topic.content,user.username,user,email where topic.PostUserName=user.username"
此发正确
tianjy 2004-04-19
  • 打赏
  • 举报
回复
"select topic.id,topic.content,user.username,user,email where topic.PostUserName=user.username"
bananasmiling 2004-04-19
  • 打赏
  • 举报
回复
sql="select t1.* ,t2.* from topic t1,user t2 where t1.id=t2.id"
conn.execute(sql)
ecobin 2004-04-19
  • 打赏
  • 举报
回复
up~

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧