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 > cartesian product without repeating pairs inversed

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-21-10, 21:36
elaich elaich is offline
Registered User
 
Join Date: Dec 2010
Posts: 5
cartesian product without repeating pairs inversed

i have a table with one column, i want to extract all pairs (a,b) where a in table and b in table and if (a,b) is on the result (b,a) must not be extracted ..
can i do that white an sql request ?
Reply With Quote
  #2 (permalink)  
Old 12-22-10, 00:43
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Code:
SELECT t1.col AS a, t2.col AS b
  FROM daTable AS t1
CROSS
  JOIN daTable AS t2
 WHERE t1.col < t2.col
of course, this only works if the col values are unique, which they would have to be because the table has only one column, so this column has to be the primary key, and therefore unique

otherwise it's not a table, it's a bag

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 12-22-10, 16:34
elaich elaich is offline
Registered User
 
Join Date: Dec 2010
Posts: 5
Yes, This is it !! Thanks
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