asp中同时调用两个表中的内容,sql语句怎么写?

来源:百度知道 编辑:UC知道 时间:2024/09/26 00:30:48
我要把表1和表2的内容同时调用出来。用union all 语句这样写的
set rs=Server.CreateObject("ADODB.Recordset")
sql="select * from table1 where username='"&username&"'" union all select * from table2 where username='"&username&"'"
rs.open sql,conn,1,1
目的:查询所有【username】发表的文章,可是不成功,请高手帮忙。在线等。
首先感谢以下各位,我再补充一些细节:table1、table2中的大多数字段都是相同的,如title,content等,此种情况该怎么做呢?

rs.open sql,conn,1,1
改成
response.write sql
然后从页面中COPY SQL语句先检查结果对不.

SELECT * FROM TABLE1 A,TABL2 B WHERE A.USERNAME= AND B.USERNAME =

SELECT * FROM TABLE A,TABL2 B WHREE A.USERNAME=B.USERNAME AND A.USERNAME=

set rs=server.CreateObject("adodb.recordset")
rs.open "select a.*,b.* from table1 a inner join table2 b on a.username=b.username where username="&username&" ",conn,1,1

select table1.colume11,
table1.colume12,
table2.colume21,
table2.colume22
from table1, table2
where table1.username=table2.username
and table1.username='"&username&"'
and table2.username='"&username&"'
-------------------
要注意的是:在ASP中要显示的数据就写成<%=rs("colume11")%>这个表示的就是table1.colume11,如果table2里面也有名称为colume11的字段,请换个字段名称或者不要select出来,否则rs显示出来的数据就会不准确。