General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 18th, 2003, 08:00 PM
johnlee_6969 johnlee_6969 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 1 johnlee_6969 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old September 19th, 2003, 08:47 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > Problem writing this SQL statement


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT