SELECT a.id,b.title FROM a left JOIN b ON b.aid=a.id and b.id>10 WHERE a.id=变量
在sql server 中测试通过正常
在access中加上 and b.id>10 连接条件就出错
Microsoft JET Database Engine 错误 '80040e14'
不支持连接表达式。
请问在access中有什么办法吗?

解决方案 »

  1.   

    是不会,对access的认识还停留在用向导。。
      

  2.   

    SELECT a.id,b.title FROM a left JOIN b ON b.aid=a.id  WHERE a.id=变量 and b.id>10
    这样呢?access好像不能在on后面加非关联的条件
      

  3.   

    刚才查了一下语法应该是不行的(参考下面),需要AB两张表的字段都存在。如果是这样的话你可以稍微改一下你的语句,将b表中id>10的数据作为中间表再跟A join. SELECT a.id,b1.title FROM a left JOIN (select * from b where id>10)b1 ON b1.aid=a.id  WHERE a.id=变量access EFT JOIN、RIGHT JOIN 操作:http://office.microsoft.com/zh-cn/access-help/HA001231489.aspx?CTT=1
      

  4.   


    这样会有问题,因为ON的执行顺序和WHERE的执行数据还是有差别的。 比如 A 1 ,10
    b 1,9得出来的值应该是:1,Nnull但是加到WHERE后面就得不到值了。 
      

  5.   

    其实我想用表连接的方法,就是不想查两次,我觉得会影响性能
    像朋友的这种写法和
    SELECT id,title FROM WHERE id=变量
    aid=rs("id")
    select * from b where id>10 and  aid=aid第一种一条语句查询两次,和写两条语句,每个语句查询一次,哪个性能更高一些呢?
      

  6.   

    顺便再问一个问题,比如显示10条记录,而表中一共1000条记录
    select top10 * form a 

    select * form a 
    for (i=0;i<10;i++)
    {
      显示记录
    }
    这两种写法,哪种性能更高一些?
      

  7.   


    SELECT a.id,b1.title FROM a left JOIN (select * from b where id>10)b1 ON b1.aid=a.id WHERE a.id=变量这个不是查两次,只是做了一个SUBQUERY,如果是SQL Server的话你看看执行计划就知道了。不过我不确定是不是在ACCESS中可以这样写。这样逻辑肯定是正确的。  
      

  8.   

    顺便再问一个问题,比如显示10条记录,而表中一共1000条记录
    select top10 * form a  

    select * form a  
    for (i=0;i<10;i++)
    {
      显示记录
    }
    这两种写法,哪种性能更高一些?
      

  9.   

    确实是语法错误,提示FROM 子句语法错误。
      

  10.   

    在SQL Server中是可以的,这里只是提供以下思路,因为没有用A,B表,所以没有实际去测试,下面的语句是我自己创建的表在SQL SERVER中可以正常运行:
    DECLARE @a table (id int,title varchar(20))
    DECLARE @b table (id int,title varchar(20))insert into @a values (1,'GM')
    insert into @b values (11,'MA')select * from @a a left join 
    (select *from  @b where ID > 10) b on b.ID = a.id where a.id = 1如果在ACCESS中不可以的话你可以创建一个VIEW
      

  11.   

    在SQL Server中是可以的,这里只是提供以下思路,因为没有用A,B表,所以没有实际去测试,下面的语句是我自己创建的表在SQL SERVER中可以正常运行:
    DECLARE @a table (id int,title varchar(20))
    DECLARE @b table (id int,title varchar(20))insert into @a values (1,'GM')
    insert into @b values (11,'MA')select * from @a a left join 
    (select *from  @b where ID > 10) b on b.ID = a.id where a.id = 1如果在ACCESS中不可以的话你可以创建一个VIEW
      

  12.   

    在SQL Server中是可以的,这里只是提供以下思路,因为没有用A,B表,所以没有实际去测试,下面的语句是我自己创建的表在SQL SERVER中可以正常运行:
    DECLARE @a table (id int,title varchar(20))
    DECLARE @b table (id int,title varchar(20))insert into @a values (1,'GM')
    insert into @b values (11,'MA')select * from @a a left join 
    (select *from  @b where ID > 10) b on b.ID = a.id where a.id = 1如果在ACCESS中不可以的话你可以创建一个VIEW
      

  13.   

    我试了,我估计可能是left join (select *from @b where ID > 10) b ACCESS不支持这么起别名不行,
      

  14.   

    SELECT a.id,b1.title FROM a left JOIN (select * from b where id>10) as b1 ON b1.aid=a.id WHERE a.id=变量
    这是最后的标准答案,起别名不加as不行