我想在同一数据库两个表中取值,应该怎么写?
代码如下<%dimsqlsql="select*fromtopicwheretotablelike'%"&session("keyword")&"%'"settopnew...
代码如下<%
dim sql
sql="select * from topic where totable like'%"&session("keyword")&"%' "
set topnew=conn_new.execute(sql)
%>
<%
tsql="select * from upload where filetype='.jpg' and url<>'' order by id desc"
set topnew=conn_new.execute(tsql)
i=0
do while not topnew.eof
i=i+1
response.write"<tr><td align=center><a href="&bbsurl&"/showbbs.asp?bd="&topnew("bd")&"%26id="&topnew("id")&"%26totable="&topnew("totable")&" target=_blank><img src=bbs/upload/"&topnew("filename")&" width=93 height=70 border=0></a></td>"
response.write"</tr>"topnew.movenext
if i=topicnum then exit do
loop
topnew.close
set topnew=nothing
%> 展开
dim sql
sql="select * from topic where totable like'%"&session("keyword")&"%' "
set topnew=conn_new.execute(sql)
%>
<%
tsql="select * from upload where filetype='.jpg' and url<>'' order by id desc"
set topnew=conn_new.execute(tsql)
i=0
do while not topnew.eof
i=i+1
response.write"<tr><td align=center><a href="&bbsurl&"/showbbs.asp?bd="&topnew("bd")&"%26id="&topnew("id")&"%26totable="&topnew("totable")&" target=_blank><img src=bbs/upload/"&topnew("filename")&" width=93 height=70 border=0></a></td>"
response.write"</tr>"topnew.movenext
if i=topicnum then exit do
loop
topnew.close
set topnew=nothing
%> 展开
1个回答
2013-10-25
展开全部
如果 两个表的字段和字段的类型一样,那么就用 union这样取select * from topic where totable like'%"&session("keyword")&"%' union select * from upload where filetype='.jpg' and url<>'' order by id desc 对果字段和字段类型不一样,那没有就把两个*的地方改一下使之两处字段的类型对应成一样就可以了如:select t1,t2 from topic where totable like'%"&session("keyword")&"%' union select u1,u2 from upload where filetype='.jpg' and url<>'' order by id desc不知道你表结构就只有用t1,t2,u1,u2代潜了 t1要和u1的类型一样,t2和u2的类型一样 就可以了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询