|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Problem writing this SQL statement
Dear all,
Problem writing this sql statement, can never get the result. Please help. I have the following tables (table1 & table2). table1 id t1member 1 m001 2 m002 3 m003 table2 id t2member svcdate 1 m001 2003-05-05 2 m001 2003-09-09 3 m002 2003-03-03 Condition a) must list all row in table1 b) append with svcdate >= today date (assume today date = 2003-09-09) Result t1member svcdate m001 2003-09-09 m002 m003 |
|
#2
|
||||
|
||||
|
Try something like:
Code:
mysql> select DISTINCT t1.member, IF(TO_DAYS(t2.date)>=TO_DAYS(NOW()) AND t1.member=t2.member,t2.date,"") as date FROM one as t1, two as t2; +--------+---------------------+ | member | date | +--------+---------------------+ | m001 | | | m002 | | | m003 | | | m001 | 2003-09-19 08:40:13 | +--------+---------------------+ I get a duplicate member when I do that, but you may at least be able to take the IF part of the query and refine the rest or add some dupe-weeding-out code. I think the IF may be helpful here, though. |
![]() |
| Viewing: Dev Articles Community Forums > Databases > General SQL Development > Problem writing this SQL statement |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|