Click here to Skip to main content
15,881,735 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have three columns named as CustomerID int, PurchaseID int, PaymentDate datetime.

each CustomerID can have multiple PurchaseIDs and Payment will be done multiple times a day.
my table data looks like as below:
[C_ID P_ID P_Date]
[c1 p1 01/01/2017]
[c2 p2 01/01/2017]
[c2 p2 01/01/2017]
[c2 p2 02/01/2017]
[c2 p3 02/02/2017]
[c3 p4 10/10/2017]

I'm trying to display distinct dates and distinct P_IDs.
for example for CustomerID c2: Display only
[c2 p2 01/01/2017]
[c2 p2 02/01/2017]
[c2 p3 02/02/2017]
these results in result table.

Could you please help me with this.
Thank you.

What I have tried:

select distinct(C_ID), * from mytable

but it doesn't gives the expected results.
Posted
Updated 29-Jun-17 17:26pm

1 solution

SQL
SELECT DISTINCT C_ID, P_ID, P_Date FROM mytable
or
SQL
SELECT C_ID, P_ID, P_Date FROM mytable
GROUP BY C_ID, P_ID, P_Date
Any of these should work.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900