第一个表 第二个表 第三个表
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
请问有没有直接查询的方法
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
请问有没有直接查询的方法
解决方案 »
- sql2005'逻辑运算符和物理运算符引用'求概念和例子.
- 简单问题,快来抢分啊!!先来先得!!利马揭帖!!!
- 求一个复杂的存储过程
- bulk insert 多个文件
- 在群集中安装SQL时出现的问题
- 问个存储过程的问题
- 提示错误:必须声明变量@n_dm
- 请大家来讨论一下“事务”对MIS系统性能的影响?我觉得在程序中大量的使用“事务”,会使程序的性能急剧下降。
- 求解,MSSQL的DB_OWNER帐户下,如何将一个文件导入数据库中,劳烦写出语句,诚谢!!<<要导入的文件为ACCSECC数据库.MDB后缀>>
- 关于存储过程的问题
- 这个问题想了很久了.来问问大家.
- 求SQL SERVER 数据库命名及设计规范,请邹建大哥指点,给小弟一份文档借鉴一下,谢谢!
from pets,owners,types
where pets.id = owners.id and pets.id = types.id
from pets,owners,types
where pets.id = owners.id and pets.id = types.id where pets.id = '你的参数'
from pets,owners,types
where pets.id = owners.id and pets.id = types.id where pets.id = '你的参数'
-------------------------------------------------------------------------------
这个是对的,你也可以用一个变量传递参数。
from pets,owners,types
where pets.id = owners.id and pets.id = types.id and pets.id = '你的参数'手误
可是我在查询分析器上试了怎么说where附近错误呀 。
owners,types
where pets.type_id = types.id and pets.owner_id = owners.id
and pets.id=?
谢谢了 按照你的思路终于搞定了