MySQL return single row of multiple invoice due for notification
Trying to create a notification mail to my clients that have invoices due.
Here is my table
Name Amount Duedate
Joe@blah 10.00 2011-04-13
Joe@blah 15.00 2011-04-13
Jill@ugg 20.00 2011-05-20
Jim@yuck 25.00 2011-04-13
Joe@blah 15.00 2011-05开发者_运维问答-20
Because Joe is in there twice, how do I supress the second joe, so I don't notify him twice. I'd like it to return only:
Joe@blah
Jim@yuck
How do i do this in mysql?
Thanks
SELECT DISTINCTROW Name FROM Table WHERE DueDate (<=> meets your criteria of when it's "due")
Since you're only selecting on Name the DISTINCTROW will only return one instance of each Name.
SELECT DISTINCT Name FROM your_table WHERE Duedate < NOW()
SELECT syntax look at DISTINCT
section
This query should give you unique names with due date falls in past or today.
Select
B.*
From
Invoicetable A,
(SELECT DISTINCT Name FROM Invoicetable WHERE Duedate <= NOW) B
where
A.Name = B.Name
精彩评论