高手们,这个让我很费解的sql查询 现在有两张表:表A 和 表B,这两张表都是新闻表,现在我想做的是,给出一个查询条件:文章标题进行模糊查询,怎么才能同时从这两张表里查询出来数据(表A和表B没有关系) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 --表结构要是一样select * from (select * from Aunion allselect * from B)aawhere 模糊条件 结构相同: select * from (select * from A union all select * from B)T where title like '%****%'结构不同: 尝试将主要信息通过别名等方式,做成相同的。 然后用结构相同的方法处理。 select * from A where 文章标题 like '%內容%'union all select * from B where 文章标题 like '%內容%' SELECT COL1,COL2,COL3 FROM A WHERE 标题 LIKE '%标题%'UNION ALLSELECT COL1,COL2,COL3 FROM A WHERE 标题 LIKE '%标题%' select * from(select news from table1union select news from table2) tbwhere news like '%世界杯%' 如果要返回其它字段,可以用下面的,a与d,b与e,c与f的类型要一样才行。select * from(select a,b,c,news from table1union select d,e,f,news from table2) tbwhere news like '%世界杯%' 谢谢nightmaple, 问题解决了。 char(6)的字段,存的全是数字,开头的0为什么自动被去掉了? 请问怎样的索引可以使"like"查询加快 关于游标与WHILE的初级问题请各位大侠批教,我是个菜鸟,谢谢! 同义词表中如何建触发器? mysql 5.0中index删不掉怎么办 谁能帮我看看,谢谢! procedure 关于联合查询的问题 错误:9003 LSN(12958:194:1)无效 SQL Server中怎样SELECT才能返回结果中的部分行,比如我只要50-100行。 SQL Server 如何在触发器插入登录的用户ID 如何建立二个表对一个表的级联删除关系?
select * from (
select * from A
union all
select * from B
)aa
where 模糊条件
结构不同: 尝试将主要信息通过别名等方式,做成相同的。 然后用结构相同的方法处理。
select * from A where 文章标题 like '%內容%'
union all
select * from B where 文章标题 like '%內容%'
UNION ALL
SELECT COL1,COL2,COL3 FROM A WHERE 标题 LIKE '%标题%'
(select news from table1
union select news from table2) tb
where news like '%世界杯%'
select * from
(select a,b,c,news from table1
union select d,e,f,news from table2) tb
where news like '%世界杯%'