Home » SQL & PL/SQL » SQL & PL/SQL » stopping duplication
stopping duplication [message #202729] Sat, 11 November 2006 08:04 Go to next message
shorinhio
Messages: 2
Registered: November 2006
Junior Member
I have a table which has customer's address town and postcode, with the customer_number being the primary key. I am trying to select the address town and postcode from the whole table, but in one case two different customers have the same address. How do I stop this duplication? This has been frustrating me and Im sure there is a simple solution.

TABLE customers

cust_no | address | town | postcode
001 | 6 new rd | coventry| CV4 8AH
002 | 6 new rd | coventry| CV4 8AH
003 |8 high st | coventry| CV5 7AF

How do I SELECT:

address | town | postcode
6 new rd | coventry| CV4 8AH
8 high st | coventry| CV5 7AF

Any help would be greatly appreciated. Thanks.
Re: stopping duplication [message #202732 is a reply to message #202729] Sat, 11 November 2006 08:22 Go to previous messageGo to next message
shorinhio
Messages: 2
Registered: November 2006
Junior Member
I have found a solution now using DISTINCT.
Re: stopping duplication [message #202746 is a reply to message #202729] Sat, 11 November 2006 11:26 Go to previous message
ab_trivedi
Messages: 460
Registered: August 2006
Location: Pune, India
Senior Member
Hi Shorinhio,

But what is the problem it might be possible that two customers have the same address.

Solution 1.
If constraint is that same address can not be possible then make address column as the unique column.

Solution 2.
Use the self join and don't print the records which are repoeated.

Bye
Ashu
Previous Topic: Counting how many times a certain character appears
Next Topic: Date formatting on table creation
Goto Forum:
  


Current Time: Fri Dec 09 19:51:31 CST 2016

Total time taken to generate the page: 0.08902 seconds