select a.day 'time'
from `good_day_money`a,`card_sale_card`b
where a.moneyOne is not NULL and a.moneyTwo is not NULL 

select a.day 'time'
from `good_day_money`a
where a.moneyOne is not NULL and a.moneyTwo is not NULL 
返回的结果为什么不一样呢?
第一种返回的比如是:
2006-01-01
2006-03-12
2006-12-12
而第二种则返回:
2006-01-01
2006-01-01
2006-01-01
2006-03-12
2006-03-12
2006-03-12
2006-12-12
2006-12-12
2006-12-12
哪为肯告诉我是为什么呢?

解决方案 »

  1.   

    第一个语句少连接条件,那两个表就是cross join,也就是产生笛卡儿乘积,只要card_sale_card有超过一条记录,就会有重复
      

  2.   

    那我该怎么办呢?我想返回的结果是所有表一里a.moneyOne is not NULL and a.moneyTwo is not NULL 的时间值,我用到关联表是因为还有其他关连条件我没有写
      

  3.   

    我的意思是,我想把所有表一里满足a.moneyOne is not NULL and a.moneyTwo is not NULL 条件的返回来,但如果我要是在加个关联条件and a.day =b.day如果这样的话返回的记录和我期望的少了,因为a中满足a.moneyOne is not NULL and a.moneyTwo is not NULL的可能是5条,而b中一共才4条记录,所以返回的就少了
      

  4.   

    纪录集颠倒了...? 
    我的意思是,我想把所有表一里满足a.moneyOne is not NULL and a.moneyTwo is not NULL 条件的返回来,但如果我要是在加个关联条件and a.day =b.day如果这样的话返回的记录和我期望的少了,因为a中满足a.moneyOne is not NULL and a.moneyTwo is not NULL的可能是5条,而b中一共才4条记录,所以返回的就少了肯定是要加的.
    改改你的语句应该可以满足你的要求.
    select a.day 'time'
    from good_day_money  a, card_sale_card b
    where a.moneyOne is not NULL and a.moneyTwo is not NULL 
          and a.day *=b.day   --这个是左连接.  lz 去看看...left join