我有兩個表的結構是這樣的:需要使用SQL查詢幫助
表
id title date
1 testing1 2001-05
1 testing2 2003-05
表B
id code date
1 aaaa 2001-01
1 bbbb 2003-01
當我連接這兩個表,我我得到三排,但我只想要2?
(query)
select distinct a.*, b.*
from table a, table b
where a.date in ('2001-05','2003-05')
and a.id=b.id
and b.date < a.date ---> I know the error is coming from here.
錯誤輸出看起來像這樣
id title date id code date
1 testing1 2001-05 1 aaaa 2001-01
1 testing1 2003-05 1 aaaa 2003-01-------this is duplicated because the date is in fact less than,
1 testing2 2003-05 1 bbbb 2003-01
正確的輸出應該是:
id title date id code date
1 testing1 2001-05 1 aaaa 2001-01
1 testing2 2003-05 1 bbbb 2003-01
你能用文字描述你試圖用你的查詢來達到什麼目的嗎? – 2011-05-13 18:36:03
我正在試圖合併表格, – NULL 2011-05-13 18:42:16
請問您可以告訴我們,**您正在使用的數據庫,版本和版本? – 2011-05-13 18:42:25