有两个表 table1结构如下
id
title
content
table2结构如下
id
content
bigclass
smallclass
sql="select id, title, content,'''''''' as bigclass,'''''''' as smallclass, ''''tbl1'''' as tbl from table1 where title like ''''%"&keyword&"%'''' or content like ''''%"&keyword&"%'''' union select id, '''''''' as title, content,bigclass,smallclass, ''''tbl2'''' as tbl from table2 where content like ''''%"&keyword&"%'''' order by id desc"
这条语句即可实现查询。 以asp为例,则通过 set rs=conn.execute(sql) while not rs.eof …… …… response.write rs("tbl")''''此值就是判断数据是哪个表的 …… …… rs.movenextwend