If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > help filtering rows which fields have the same value in another row

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-26-07, 21:03
adamjameson adamjameson is offline
Registered User
 
Join Date: Jun 2007
Posts: 2
help filtering rows which fields have the same value in another row

I am trying to figure out how to make my select statment

here is the table
Table
--------
col1 col2

1 2
2 1
3 4
4 3
1 4
4 1



What I would like to do is creat a select statment which will return only 1 row
if any other row if there is another row which col1 matches current rows col2
example the results would be returned like this

col1 col2
1 2
3 4
1 4

so the select statment filters out any of the other rows where the
col 1 was equal to the other rows col2 and the col2 was equal to that same other rows col 1.

I am sure the answer is simple I cant wrap my head around it.

Adam
Reply With Quote
  #2 (permalink)  
Old 06-27-07, 06:25
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Code:
select this.col1 
     , this.col2
  from daTable as this
inner
  join daTable as that
    on that.col2 = this.col1
   and that.col1 = this.col2
 where this.col1 < this.col2
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 06-27-07, 09:33
adamjameson adamjameson is offline
Registered User
 
Join Date: Jun 2007
Posts: 2
Thumbs up thanx

Your brilliant!
Reply With Quote
  #4 (permalink)  
Old 06-27-07, 09:38
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
thank you, thank you, i'll be here all week

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On