ASP两个表中查询数据

来源:百度知道 编辑:UC知道 时间:2024/06/04 03:20:52
一个表WL 有三个字:ID wlname wlP .另一个wuliu表 中有两个: ID Wcompany

现在是要在读取出表WL中数据时同读出wuliu表中所有wlname=Wcompany的数据!有谁可给我一个解决方案?
一楼的朋友的方法可行,但是得出的数据是全部记录的.没有达到条件后的哦,应该怎么样的呀?

<%
set rs=server.createobject("adodb.recordset")
sql="select * from WL order by id desc"
rs.open sql,conn,1,1
do while not rs.eof
%>
=================================================
ID
<%=rs("ID")%>
wlname
<%
set rs1=conn.execute("select * from wuliu where Wcompany="&rs("wlname")&"")
response.write rs1("Wcompany")
set rs1=nothing
%>
=================================================
<%
rs.movenext
if rs.eof then exit do
loop
rs.close
set rs=nothing
%>
'呵呵,看明白就可以用了

select * from wl left join wuliu on wl.wlname= wuliu.Wcompany
----------
你说的就是要WL的全部记录和wulname满足条件的记录嘛。如果这样不是你要的,试试
select a.字段1,a.字段2,...,b.字段1,b.字段2... from wl a,wuliu b where a.wlname= b.Wcompany

楼主还不如在数据库中建立一个符合条件的视图,然后查询视图。

这样就行了不用Join
select * from