有两张表,一个是表event,另一个是表location,使用join和不使用join都能得到期望的结果,如下所示:
使用join
select e.id, e.name, e.start_date, e.duration, l.id, l.name
  from event e
  join location l on e.location_id = l.id
 where e.id = 2;
 
不使用join
 select e.id, e.name, e.start_date, e.duration, l.id, l.name
  from event e,location l
  where e.location_id = l.id 
 and e.id = 2;我的问题是使用和不使用join在实现原理上有什么区别吗?使用join有什么好处吗,比如在效率上哪个更有优势?能详细说一下吗?

解决方案 »

  1.   

    你这样用的话,加不加join完全一样。
    区别在于有时候可能会专门指定外连接。
      

  2.   

    你2个 sql实际上是一样的
    以前sql的写法是用where,现在sql的写法是用join
      

  3.   

    应该是没什么区别。 where子句中联接表,是oracle   9i之前,在查询中执行联接的惟一方式。 自然连接、内连接、外联接等,都是后来出现的新的联接语法。语法不同罢了
      

  4.   

    select * from tb1,tb2 where tb1_id=tb2_id(+);
      

  5.   

    是有区别的
    你看不到有什么区别,那是因为你的e.location_id   和  l.id 肯定是一一对应的,
    如果e.location_id   和  l.id不是一一对应的话,就会显示出区别来的
    比如说你的e.location_id   是唯一的,e.location_id=10,而l.id中没有匹配的值,
    那么,在有join 时候,在e.location_id=10后对应的l.id记录显示为null
    而在不用join 时,不会显示这条记录