2017淘宝大学视频教程:asp中怎么查询rycontent表中rycontent_id等于title表中id的所有信息!查询语句怎么么写?????急!!!!

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/05 09:10:49
asp中怎么查询rycontent表中rycontent_id等于title表中id的所有信息!查询语句怎么么写?????急!!!!

先把title表中的所有ID值存到数组title中,然后:sql2="select * from rycontent where rycontent_id="&title(i)

明白了吗?

<%
set conn=server.CreateObject("adodb.connection")
connsrt="dbq="+server.MapPath("..\db\#db.mdb")+";driver={microsoft access driver (*.mdb)};"
conn.open connsrt
%>
<%
set rs= server.CreateObject ("Adodb.recordset")
sql="select * from title"
rs.open sql,conn,1,1
%>
<%
dim title()
for i=0 to rs.recordcount-1
redim title(i+1)
next

for i=0 to rs.recordcount-1
title(i)=rs("id")
rs.movenext
next

for i=0 to ubound(title)

set rs2= server.CreateObject ("Adodb.recordset")
sql2="select * from rycontent where rycontent_id="&title(i)
rs2.open sql2,conn,1,1
do while not rs2.eof
response.write rs2("id")&"<br>"
rs2.movenext
loop
next

conn.close

%>

SELECT a.* FROM rycontent a,title b WHERE a.rycontent_id = b.id

多表查询最好这样写。

SELECT rycontent.* FROM rycontent, title WHERE rycontent.rycontent_id = title.id