Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7775889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:44:20+00:00 2026-06-01T17:44:20+00:00

Following is the sample o/p of the SQL query – BUG_ID | LINKED_BUG_ID ———–|—————–

  • 0

Following is the sample o/p of the SQL query –

  BUG_ID   |  LINKED_BUG_ID
-----------|-----------------
3726       |  45236
45236      |  3726
3726       |  45254
45254      |  3726
3726       |  45402
45402      |  3726
3726       |  1182
1182       |  55745

In my SQL o/p, there are two rows out of which one row is redundant. e.g Bug Id 3726 and Linked Bug Id 45326 and Bug Id 45326 and Linked Bug Id 3726 are present twice in the o/p, out of which we need only one row and ignore such kind of duplicate rows (having either of a value repeated in Bug Id column or Linked Bug Id column), without affecting the o/p containing the distinct value.

Currently I can identify such duplicate rows using following query, but I need only one single row out of such duplicate rows.

SELECT 
  BUG_ID, 
  LINKED_BUG_ID, 
  CASE 
    WHEN BUG_ID IN (select LINKED_BUG_ID FROM MY_BUG_LINKS) AND 
      LINKED_ISSUE_ID IN (SELECT BUG_ID FROM MY_BUG_LINKS) 
    THEN 'true' ELSE 'false'  
  END AS EQUAL 
FROM MY_BUG_LINKS;

Following is the SQL query that I use in my code for fetching all the rows (which includes even duplicate rows)

SELECT BUG_ID, LINKED_BUG_ID FROM MY_BUG_LINKS;

How can I avoid fetching redundant duplicate rows at the database level itself or in my java code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:44:21+00:00Added an answer on June 1, 2026 at 5:44 pm

    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:

    SELECT DISTINCT
      CASE WHEN BUG_ID > LINKED_BUG_ID THEN LINKED_BUG_ID ELSE BUG_ID AS BUG_ID,
      CASE WHEN 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to translate following simple sql query into Linq to NHibernate: SELECT NewsId
While going through SQL profiler, I noticed the following query generated by EF4. exec
I have the following SQL statement sample: SELECT DISTINCT [CommentNdx] ,[CommentsText] ,[DateTimeAdded] FROM [dbo].[CommentTable]
The sql injection will work only when my query looks like below sample SELECT
I created the following simple PL/SQL stored procedure example to ask a specific question.
i m having following type of simple sql server table Here I want to
I have the following code that fills dataTable1 and dataTable2 with two simple SQL
I have the following sample code which doesn't seem to want to run. import
I have the following sample data: Id Name Quantity 1 Red 1 2 Red
I have the following sample of data to insert into tables(from parent to child,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.