Ignore Redundant Values Fetched From Database
Following is the sample o/p of the SQL query - BUG_ID | LINKED_BUG_ID -----------|----------------- 3726 | 45236 45236 | 3726 3726 | 45254 45254 | 37
Solution 1:
If this is merely about treating (B, A) as a duplicate of (A, B) and you do not particularly care whether the row returned will be (A, B) or (B, A), you could do something like this:
SELECTDISTINCTCASEWHEN BUG_ID > LINKED_BUG_ID THEN LINKED_BUG_ID ELSE BUG_ID AS BUG_ID,
CASEWHEN BUG_ID > LINKED_BUG_ID THEN BUG_ID ELSE LINKED_BUG_ID AS LINKED_BUG_ID
FROM MY_BUG_LINKS;
That is, if BUG_ID has a greater value than LINKED_BIG_ID, the query swaps the two IDs, otherwise the values are returned unchanged. Therefore, (A, B) and (B, A) always produce duplicate rows (both would be either (A, B) or (B, A)), and DISTINCT makes sure there's none in the final result.
Post a Comment for "Ignore Redundant Values Fetched From Database"