小人得志,君子道校:sql 语句求解 在线等待 请大侠们指点

来源:百度文库 编辑:中科新闻网 时间:2024/04/28 06:08:15
急求解 谢谢大侠
我有三个表
views news rout
现需要一起查询
表views 字段 view_name , price , view_order ,view_detail
表 news 字段 title , filename , addnewsname , newspath , content
表 rout 字段 route_name , route_outtime , route_price , jingdian

然后对 表views中 字段view_name,view_detail
表news中 字段title , content
表rout中 字段route_name , jingdian
的值进行关键字的查询

我要做一个站内搜索 请大侠们告知这个的sql语句怎么写

sql 数据库
那这样的查询结果不就成了先是显示表views 然后是表news 最后是表rout的了吗? 如果我想按三个表里的日期排列 怎么办?? 顺序是按哪条数据日期靠前排列,这样的话这样写成吗?

可以用union,假设要搜索的关键字为"keyWord"
构造sql如下:
select view_name,view_detail from views where view_name like '%keyWord%' or view_detail like '%keyWord%' union select title , content from news where title like '%keyWord%' or content like '%keyWord%' union select route_name , jingdian from rout where route_name like '%keyWord%' or jingdian like '%keyWord%'

回复楼下的:union不需要相同名字的字段.只需要保证字段数目相同,且类型对应就可以了.事实胜于雄辩...

select v.view_name, v.detail, n.title, n.content, r.route_name,r.jingdian
from
views v,
news n,
rout r
where
v.name=?
and n.title=?
and r.rount_name=?

这个对,我同意

这个方法是个经验,书上没有介绍,你就试试吧!

select v.view_name, v.detail, n.title, n.content, r.route_name,r.jingdian
from
views v,
news n,
rout r
where
v.name=?
and n.title=?
and r.rount_name=?

你的三张表没有外键关联,不能联合查询.
只能单张表查询.

是啊 !!

没有相同中的字段用什么union查询了。楼上懂不懂SQL