有两个表:table1和table2结构完全相同(id,name_id,age_id,birthday),以及表name(name_id,name);age(age_id,age),这两个表分别与table1和table2有外键关系但table1和table2 没有外键关系,我创建了一个视图view1包含(id,name,age,birthday);id为主键;SQL语句如下:
create view view1(id,name,age,birthday)
as
((select table1.id,name.name,age.age,table1.birthday from table1,name,age where name.name_id=table1.name_id and age.age_id=table1.age_id)
union
(select table2.id,name.name,age.age,table1.birthday from table2,name,age where name.name_id=table2.name_id and age.age_id=table2.age_id))
创建视图成功!视图中有id=1;name='李华';的一项,我用:select * from view1 where id=1 可查出所有项信息;可是用:select * from view1 where name='李华'只显示字段名而无内容什么原因呀????

解决方案 »

  1.   

    select * from view1 where name like '%李华%'  试试有数据嘛?
      

  2.   

    知道了!
    select * from view1 where name='李华'  中 ‘李华’有空格!下面sqlselect * from view1 where rtrim(ltrim(name))='李华' 
      

  3.   

    不是这个问题,table1 的都可以查出,只有table2 的有问题,是不是union 语句有问题呀?错在哪呢????
      

  4.   

    union 后面的那个语句应该是table2.birthday from table2 你写成 table1.birthday from table2
      

  5.   

    问题还没解决!请大侠们帮帮忙!!!(table2.birthday from table2 程序中无错,我在文本中输错了,不好意思!)