表A
字段 id content type
     1   1234     0
     2   1235     0
     3   1236     0
     4   1337     0表B
字段 id  content tt
     1    1235   1
     2    1236   1
     3    1222   1
     4    1233   1要求对2张表进行搜索
1:表A和表B.没有关系
2:用关键字匹配的时候,只要表A或者表B有满足的条件就都显示出来!
3:显示出来的记录,我要知道那条记录是哪张表里的记录
例如:
我输入123的时候与content匹配,显示出来的结果应该是
table  id  content
 A      1    1234
 A      2    1235
 A      3    1233
 b      1    1235
 b      2    1236
 b      4    1233
我用的是oracle9.2

解决方案 »

  1.   

    select ta tab,id,content from tableA ta where content like '123%' union
    select tb tab,id,content from tableB tb where content like '123%';
      

  2.   

    select "A" as tab,id content from A where content like '%123%'
    union all
    select "B" as tab,id content from B where content like '%123%'
      

  3.   


    select "A" as table,id,content from A where content like '123%' union select "B" as table,id,content from B where content like '123%'
      

  4.   

    2楼正解.
    增加一个常数作来标识表名.
    两个表因为结构一致.那就union一下就ok了.