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 4608562
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:51:46+00:00 2026-05-22T00:51:46+00:00

Is there a simple way on Oracle to query unique combinations of n fields.

  • 0

Is there a simple way on Oracle to query unique combinations of n fields. I Have very simple two-field solution:

CREATE TABLE combinations AS
SELECT 1 AS n 
  FROM DUAL
UNION ALL
SELECT 2
  FROM DUAL;

Querying for unique combinations:

SELECT LEAST(x.a, x.b), 
       GREATEST(x.a,x.b) 
  FROM (SELECT c1.n a, 
               c2.n b 
          FROM combinations c1
    CROSS JOIN combinations c2
         WHERE c1.n <> c2.n) x
GROUP BY LEAST(x.a, x.b), GREATEST(x.a,x.b);

From this query 1,2 and 2,1 are considered the same. Unfortunately it doesn’t work for 3-field structure (for example 1,2,3 must be considered the same as 3,1,2 because ordering of values doesn’t matter). Does Oracle analytic functions provide appropriate solution for this question? Could you suggest some particular Oracle analytic function?

  • 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-05-22T00:51:47+00:00Added an answer on May 22, 2026 at 12:51 am

    Your query for 2 columns could be rewritten like this:

    SELECT
      c1.n,
      c2.n
    FROM combinations c1
      INNER JOIN combinations c2 ON c1.n < c2.n
    

    For 3 columns you would then need to make some additions (highlighted in bold):

    SELECT
      c1.n,
      c2.n,
      c3.n
    FROM combinations c1
      INNER JOIN combinations c2 ON c1.n < c2.n
      INNER JOIN combinations c3 ON c2.n < c3.n
    

    I’m sure you can now easily guess how to scale this for more columns.

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

Sidebar

Related Questions

Is there a simple way to have isometric projection? I mean the true isometric
I have a simple query using JDBC of an Oracle database which is proving
I'm using Oracle, and I have a very large table. I need to check
I'm using Oracle 10g. I have a table with a number of fields of
Is there a simple way to see assigned shortcuts with given prefix? Something similar
Is there a simple way to work with C++ objects directly from C? I
Is there a simple way to convert MP3 to WAV in vb2005? what i
Is there a simple way or method to convert a Stream into a byte[]
Is there a simple way of redirecting serial port output to a file, that
Is there a simple way of rendering to a BufferedImage in Java3D? I know

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.