Web Hosting Talk







View Full Version : Help on mysql query


kapot
11-09-2003, 05:03 AM
I have a table called TRANSACTION, it has some fields :

REGDATE - date of the transaction
WHAT - a string (NOT UNIQUE)
CUSTOMER - customer code

I want to query all WHAT that the date of the transaction was 15 days before.

So, my sql query is :

SELECT WHAT FROM TRANSACTION WHERE REGDATE < Now() -INTERVAL 15 DAY

But, because of WHAT is not unique, then I could receive some duplicates (customer can send some WHAT in the same REGDATE).

How can I query only the unique WHAT ? I need to list all WHAT (uniquely) that the date transaction was 15 days before.

Please help,

Thanks

null
11-09-2003, 05:07 AM
SELECT DISTINCT WHAT FROM TRANSACTION WHERE REGDATE < Now() -INTERVAL 15 DAY

http://www.mysql.com/doc/en/SELECT.html

The options DISTINCT, DISTINCTROW and ALL specify whether duplicate rows should be returned. The default is (ALL), all matching rows are returned. DISTINCT and DISTINCTROW are synonyms and specify that duplicate rows in the result set should be removed.