Connecting Tech Pros Worldwide Help | Site Map

query to get a unique pair of details from db

Newbie
 
Join Date: May 2007
Posts: 1
#1: May 22 '07
I have a table MyTable with multiple fields.
eg : ip, gw,id where id is the primary key
I need unique ip,gw pairs
eg:
ip gw id
1.1 a 1
2.1 b 2
3.1 c 3
1.1 a 4

I need to eliminate duplicate pairs ie 1.1 a
I am not able to build such a query
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,745
#2: May 22 '07

re: query to get a unique pair of details from db


Moving this thread to the MySQL Forums.
Please try to refrain from posting questions in the Article section.

MODERATOR
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,745
#3: May 22 '07

re: query to get a unique pair of details from db


Hi, and welcom to TSDN.

Do you need your ID column?
If not you could make the other two fields act as Primary Key. Then they would not be able to accept duplicate values.

E.g:
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE myTable
  2. (
  3.   colA VARCHAR(255) NOT NULL,
  4.   colB INT NOT NULL,
  5.   Primary Key(colA, colB)
  6. )
  7.  
Reply