| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 319 人关注过本帖
标题:如何多表联合查询 ID为数组
只看楼主 加入收藏
waterchan
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-3-14
收藏
 问题点数:0 回复次数:0 
如何多表联合查询 ID为数组
表名1:Orders
ID    p_ids        time
1    1,2,3        2012-05-05
2    4            2012-05-05
3    5,6          2012-05-05
4    7,8          2012-05-05


表名2:Attribute
ID    name
1    大众
2    奔驰
3    奥迪
4    丰田
5    大众
6    奥迪
7    标致
8    雪铁龙


要读取出两个表的数据
Attribute表里的ID 是和Orders表的 p_ids(字段)关联

'我之前的查询方法是用循环
程序代码:
set o_rs=Server.CreateObject("Adodb.Recordset")
    o_sql="Select * from Orders order by id desc"
    o_rs.open o_sql,conn,1,1
    while not o_rs.eof
        a_list = split(o_rs("p_ids"),",")

        for i = 0 to UBound(a_list)
            set A_rs=Server.CreateObject("Adodb.Recordset")
            A_sql="Select * from Attribute where id="&a_list(i)
            A_rs.open A_sql,conn,1,1
           
            .....读数据....
           
            A_rs.close
            set A_rs=nothing
        next
    o_rs.movenext
    wend
o_rs.close
set o_rs = nothing
现在想用多表查询  只用一句SQL语句
下面这句Orders表的p_ids字段里的数据为数组
sql="Select * from Orders,Attribute where (Attribute.id in (Orders.p_ids)) order by Attribute.id desc"
    Set rs=Server.CreateObject("Adodb.Recordset")
    rs.open sql,conn,1,1

查询后出错.



直接用一句SQL语句 请问如何查?


搜索更多相关主题的帖子: 查询 如何 
2012-03-14 22:18
快速回复:如何多表联合查询 ID为数组
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013260 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved