I have two tables structured like this:
table a
id title date
1 testing1 2001-05
1 testing2 2003-05
table b
id code date
1 aaaa 2001-01
1 bbbb 2003-01
When I join these two tables, I am getting three rows, but I only want 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.
wrong output looks like this
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
correct output should be:
id title date id code date
1 testing1 2001-05 1 aaaa 2001-01
1 testing2 2003-05 1 bbbb 2003-01
1 Answer