I have two columns, source and destination in table Hyperlink, to store the source and destination of hyperlinks.
source | destination
--------------------
a | b
b | c
c | d
c | b
There are two hyperlinks involving both b and c. The difference between the two hyperlinks is the direction of the hyperlink. However, my objective is to retrieve unique hyperlinks, no matter which direction. So for hyperlinks such as from b to c and from c to b, I just want to select one of them. Any one would do.
So my results should look like this:
source | destination
--------------------
a | b
b | c
c | d
So far I am able to implement this in Java, with some processing before I execute SQL statements using JDBC. However, this is going to be very tedious when the table becomes very large.
I wonder if there is anyway I can do this in SQL instead.
I tried SELECT DISTINCT source,destination FROM Hyperlink but it returns me the unique permutations. I need the unique combinations.
Thanks!
This is easily achievable with the least() and greatest() operator, but as MySQL doesn’t support them you need to use a CASE construct to get the smaller/greater one. With two columns this is ok, but this solution gets pretty messy once more columns are involved