李全有演员:SQL问题 如何从多表中查询数据

来源:百度文库 编辑:高考问答 时间:2024/04/29 18:54:11
select * from tab1,tab2,tab3 where name="张三"

分别从三个表tab1,tab2,tab3中查找是不是含有 张三 的记录已存在,主要是用来判断是不是存在。
已存在就关闭,不存在就写入新记录
三个表的字段都相同

if not Exist(select * from tab1,tab2,tab3 where name="张三"

)
go
insert into table1(name),Values('张三')
insert into table2(name),Values('张三')
insert into table3(name),Values('张三')
go

做三次判断,记数或者看结果集是不是为空
哪有把三个写一块的?
那可是笛卡儿积
写个name条件肯定也报错啊
没有指定那张表

select * from tab1,tab2,tab3 where name="张三"
这个语句能运行吗?

你的三个表之间有关系吗?没关系不好查

使用 联合查询