t1:
id     id2     id3   name  age
1      2       3      kaka  24t2:
id   car   address
1     bmw     bj
2     benz    tjt3:
id    price
1      12000
2       4323
3     10922通过什么语句能得到如下的结果:
id   car   address   price   name  age
1    benz    tj      10922    kaka  24      

解决方案 »

  1.   

    select distinct t1.id,car,address,price,name,age from t1,t2,t3 where t1.id2=t2.id and t13.id=t3.id
      

  2.   

    select t1.id as id,t2.address as address, t3.price as price ,t1.name as name,t1.age as age from t1,t2,t3 where t1.id2=t2.id and t1.id3=t3.id and t1.id=1
      

  3.   

    distinct
    这个是做什么用的?t1.id
    是因为3个表有重复的id字段名才加个表前缀把?上边的语句再加个条件,如果我得到100条符合上面条件的数据,我想取出26-30的那些数据,应该这么写把
    select distinct t1.id,car,address,price,name,age from t1,t2,t3 where t1.id2=t2.id and t13.id=t3.id limit 26,5
    那么在换个方式,我先取出t1表的26-30的那些数据,然后在从这5条数据里以上条件的数据该怎么写?这么查询的效率怎么样,比如我查个t1有2000条数据,t2有20条,t3有20条的库,是不是每一条数据都要经过联表处理?有没有更好的方式实现这个查询?
      

  4.   

    2楼的这个  t1.id=1 限定条件加上去是不是无论怎么样联表都只有一个结果或者没有结果.实际用处只能作为数据的存在性判断用吧?
      

  5.   

    distinct 去掉出现的重复t1.id 对,因为有相同字段字
    select * from t1 limit 26select distinct t1.id,car,address,price,name,age from t2,t3,(select * from t1 limit 26,5) t1 where  t1.id2=t2.id and t13.id=t3.id
      

  6.   

    select distinct t1.id,car,address,price,name,age from t2,t3,(select * from t1 limit 26,5) t1 where  t1.id2=t2.id and t1.id3=t3.id