高手请进,一个空表问题!

ponderlon 2004-10-14 10:01:00
已知: table1, table2,其中table1有数据,table2没有数据,table1和table2没有任何关联。

现在,我想得到的数据是:

当table2.col2='value2'时,得到table2.col1

取得select * from table1 where table1.col1 > table2.col1

问:
我写的sql是:

select *
from table1,table2
where table2.col2='value2'--错误原因
and table1.col1 > table2.col1(+)

但是这个查询是空表。
请问应该怎么写?


...全文
171 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
zwj0712 2005-01-18
  • 打赏
  • 举报
回复
注意你的table2.col2='value2','value2'要分大小写!
caodiablo 2005-01-18
  • 打赏
  • 举报
回复
关键是where 后面的那个 null

要不然当然没有数据。。。

看我上面的那段sql
aku0708 2005-01-13
  • 打赏
  • 举报
回复
table2没数据!!!
(table2.col2='value2')???
baojianjun 2005-01-13
  • 打赏
  • 举报
回复
table2没有数据,table2.col2='value2'又怎麼可能
lynx 2005-01-13
  • 打赏
  • 举报
回复
table1和table2没有任何关联??? 那就是没有where了?
试试看吧:

select decode(t2.col2,'value2',t2.col1,t2.col2),.....其他字段
from table1 t1,table2 t2
where table1.col1 > table2.col1(+)
ahalf 2005-01-13
  • 打赏
  • 举报
回复
除非table2只有一个col1
GerryYang 2005-01-13
  • 打赏
  • 举报
回复
听不懂,也看不懂.
skystar99047 2005-01-12
  • 打赏
  • 举报
回复
说清问题先
yxxx 2005-01-12
  • 打赏
  • 举报
回复
对,先说说清楚错误,及期望答案
NinGoo 2005-01-12
  • 打赏
  • 举报
回复
select *
from table1,table2
where table2.col2='value2'
and table1.col1 > table2.col1(+)

这个语句执行并没有错误啊,返回0条数据

楼主你的错误是什么?或者说你想返回什么样的数据?
NinGoo 2005-01-12
  • 打赏
  • 举报
回复
楼上的,那个是左连接吧,呵呵
caodiablo 2005-01-12
  • 打赏
  • 举报
回复
select *
from table1,table2
where (table2.col2 is null or table2.col2='value2')
and table1.col1 > table2.col1(+)

不明白 你为什么要用右连接?
snowdog19820810 2005-01-12
  • 打赏
  • 举报
回复
我也想知道

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧