两个表结构如下:
table1(id,userid)        无主键(有可能1个id对应多个userid)
table2(id,acountid,fileid) id为主键table1中的id来源与table2中的id求查询 满足userid= 条件1 或 acountid= 条件2 的所有fileid 的sql语句

解决方案 »

  1.   

    SELECT 
    *
    FROM 
    TABLE1 A
    JOIN
    TABLE2  B ON A.ID=B.ID
    WHERE
    A.USERID=? OR B.ACOUNTID=??
    這樣?
      

  2.   

    select distinct b.fileid 
    from table1 a,table2 b
    where a.id=b.id and (a.userid=条件1 or b.acountid=条件2)
      

  3.   

    select fileid from table1,table2 where table1.id=table2.id and (userid=条件1 or acountid=条件2)
      

  4.   

    SELECT *FROM TABLE1 A JOIN TABLE2  B ON A.ID=B.ID WHERE A.USERID=?
      

  5.   


    select n.fileid from table1 m , table2 n where m.id = n.id and userid= 条件1 and acountid= 条件2
      

  6.   

    我怀疑你是:m.userid = n.id select n.fileid from table1 m , table2 n where m.userid = n.id and userid= 条件1 and acountid= 条件2
      

  7.   

    SELECT fileid FROM table1 JOIN table2 ON(table1.id =table2.id)
    WHERE userid ='条件'  or acoutid ='条件'
      

  8.   

    好像都有点问题,主要是在两个表的关联上,因为table2中的有的id可能在table1中没有,
    如果table2的某条记录满足acountid= 条件2,但该记录的id没有在table1中出现,
    按上面的where table1.id = table2.id 条件就会漏掉该条记录。
      

  9.   

    select fileid from table2 where id in (
    select distinct table2.id from table2 right join table1 on table1.id = table2.id where table1.userid=条件1 or table2.acountid=条件2)
      

  10.   

    SELECT * FROM TABLE1 A RIGHT JOIN TABLE2  B ON A.ID=B.ID
    WHERE
    A.USERID=xx OR B.ACOUNTID=xx
      

  11.   

    select fileid from table2 where id in ( 
    select distinct table2.id from table2 right join table1 on table1.id = table2.id where table1.userid=条件1 or table2.acountid=条件2) 
      

  12.   

    select fileid from table2 where id in ( 
    select distinct table2.id from table1 right join table2 on table1.id = table2.id where table1.userid=条件1 or table2.acountid=条件2) 
      

  13.   


    select table2.fiele
    from table1,table2
    where table1.id=table2.id and (userid= 条件1 or acountid= 条件2)
      

  14.   

      SELECT *
      FROM TABLE2 A LEFT JOIN TABLE1 B ON (A.ID=B.ID)
      WHERE A.USERID=?? OR A.ACOUNTID=??
      

  15.   


    select distinct fieldid
    from table2 t2
    where accountid = con2
    or exists
    (select id 
    from table1 t1
    where userid = con1 
    and t1.id = t2.id)
    con1=条件1
    con2=条件2
      

  16.   


    在表比较大的时候这个效率比join要高
      

  17.   

    select fileid from table2 where id in (
    select distinct table2.id from table1 right join table2 on table1.id = table2.id where table1.userid=condition1 or table2.acountid=condition2)