日期:2014-05-18  浏览次数:20415 次

多表多字段查询怎么写呢?
我有表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 表1
union 
select  地址 as url from 表2
union 
select   路径 as url from 表3
) v where url like'%123.jpg%'