首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

多表多字段查询如何写呢

2012-03-28 
多表多字段查询怎么写呢?我有表1,表2,表3表1有字段 图片地址表2有字段 地址表3有字段 路径(设计数据库的脑

多表多字段查询怎么写呢?
我有表1,表2,表3

表1有字段 图片地址
表2有字段 地址
表3有字段 路径

(设计数据库的脑袋让驴踢了....)

现在我有一文件 123.jpg

怎么查询在三张表里对应的字段是否存在?

只要确定是否存在就可以..

[解决办法]
if exists(select 1 from (select 图片地址 from tab1 union all select 地址 from tab2 ...) a where ....)

[解决办法]
表1有字段 图片地址
表2有字段 地址
表3有字段 路径

select 对应的字段from tbla where 对应的字段='123.jpg'
union all
select 对应的字段from tblb where 对应的字段='123.jpg'
union all
select 对应的字段from tbl where 对应的字段='123,jpg'

有结果证明存在,没结果证明不存在
[解决办法]

SQL code
select * from (select  图片地址 as url  from 表1union select  地址 as url from 表2union select   路径 as url from 表3) v where url like'%123.jpg%' 

热点排行