第一个表        第二个表         第三个表
pets(宠物)      owners(宠物主人) types(宠物类型)
           
id     pk       id               id
name            name             name
birth_date      ..               ..
type_id         ..               ..
owner_id我现在就想给他一个宠物的id就能查询出
pets.id,   pets.name,  pets.birth_date,  owners.id,  types.id我只会两个表之间的联合查询 请问有没有直接查询的方法
第一个:
select pets.id,pets.name,pets.birth_date,owners.name from pets join owners on(pets.owner_id=owners.id)where pets.id=1第二个:
select types.name from pets join types on(pets.type_id=types.id)where pets.id=1
请问有没有直接查询的方法

解决方案 »

  1.   

    select pets.*,owners.*,types.*
    from pets,owners,types
    where pets.id = owners.id and pets.id = types.id
      

  2.   

    select pets.*,owners.*,types.*
    from pets,owners,types
    where pets.id = owners.id and pets.id = types.id where pets.id = '你的参数'
      

  3.   

    用两个where对吗  我怎么试了说错误呀。//
      

  4.   

    select pets.*,owners.*,types.*
    from pets,owners,types
    where pets.id = owners.id and pets.id = types.id where pets.id = '你的参数'
    -------------------------------------------------------------------------------
    这个是对的,你也可以用一个变量传递参数。
      

  5.   

    select pets.*,owners.*,types.*
    from pets,owners,types
    where pets.id = owners.id and pets.id = types.id and pets.id = '你的参数'手误
      

  6.   

    我现在正在写jsp就是想传个参数然后进行查询。。
    可是我在查询分析器上试了怎么说where附近错误呀 。
      

  7.   

    select pets.id,pets.name,pets.birth_date,owners.name,types.name from pets,
    owners,types 
    where pets.type_id = types.id and pets.owner_id = owners.id 
    and pets.id=?
    谢谢了 按照你的思路终于搞定了