两个表在同一个数据库中,怎么从一个表中取出对应的id?
我做了一个留言板,同一数据库中有留言表guest和回复表reply
reply数据表中有一个对应留言表id的zhuid.
现在后台想在同一个表单中显示对应留言的回复内容却取不出对应留言的zhuid,请大虾指教
<%
sql= "select * from guest order by id desc "
set rs=server.createobject( "adodb.recordset ")
rs.open sql,conn,1,1
rid=request( "id ")
set rrs=server.createobject( "adodb.recordset ")
rsql= "select * from reply where zhuid= "&rid
rrs.open rsql,conn,1,1
------解决方案--------------------列出所有数据:
Select a.*,b.* From [guest] a Left outer join [reply] b on a.id=b.zhuid order by a.id desc
列出指定数据:
Select a.*,b.* From [guest] a Left outer join [reply] b on a.id=b.zhuid Where a.id=?