All possible combinations of 23 columns in a table.

Hi,
We have a table as follows;
CREATE TABLE ALL_PROD_COMB_TMP
HDLM_ID NUMBER(10),
MULTIPATH_ID NUMBER(10),
TRUE_COPY_ID NUMBER(10),
UVM_ID NUMBER(10),
TUNING_ID NUMBER(10),
CLUSTER_ID NUMBER(10),
MIDDLEWARE_ID NUMBER(10),
TAPE_ID NUMBER(10),
THIRD_PARTY_ID NUMBER(10),
NAS_ID NUMBER(10),
HBA_ID NUMBER(10),
BCM_ID NUMBER(10),
VOLUME_MIGRATION_VERSION_ID NUMBER(10),
TIERED_STO_MGR_VERSION_ID NUMBER(10),
HDPS_ID NUMBER(10),
SERVER_ID NUMBER(10),
OS_ID NUMBER(10),
DWDM_ID NUMBER(10),
EXTENDER_ID NUMBER(10),
SWITCH_ID NUMBER(10),
INTERFACE_ID NUMBER(10),
HUR_ID NUMBER(10),
STORAGE_FAMILY_ID NUMBER(10)
The data in the table is as follows;
For formatting purpose the table data is shown in transposed form.
Serial No. Column Name Data Value
1     HDLM_ID                    377     586               
2     MULTIPATH_ID               142     357               
3     TRUE_COPY_ID               1     87     12          
4     UVM_ID                    89     79               
5     TUNING_ID               10     9     8          
6     CLUSTER_ID               3     327     638          
7     MIDDLEWARE_ID                         
8     TAPE_ID                    3     47     54          
9     THIRD_PARTY_ID               3                    
10     NAS_ID                    12     91     1          
11     HBA_ID                    300     400               
12     BCM_ID                    14                    
13     VOLUME_MIGRATION_VERSION_ID     13     12               
14     TIERED_STO_MGR_VERSION_ID     1     2               
15     HDPS_ID                    10     100               
16     SERVER_ID               3     4               
17     OS_ID                    2     7               
18     DWDM_ID                    1                    
19     EXTENDER_ID               520                    
20     SWITCH_ID               4                    
21     INTERFACE_ID               2     1     3     4     
22     HUR_ID                    2     1     3     4     5
23     STORAGE_FAMILY_ID          2
Now we have another table named ALL_PROD_COMB having the same structure as that of ALL_PROD_COMB_TMP. In this ALL_PROD_COMB we need all the possible combinations of all the column values from ALL_PROD_COMB_TMP.
We tried the following thing;
insert into
     all_prod_comb (
     hdlm_id           
                                   ,multipath_id           
                                   ,true_copy_id           
                                   ,uvm_id                
                                   ,tuning_id           
                                   ,cluster_id           
                                   ,middleware_id
                                   ,tape_id
                                   ,third_party_id
                                   ,nas_id
                                   ,hba_id
                                   ,bcm_id
                                   ,volume_migration_version_id
                                   ,tiered_sto_mgr_version_id
                                   ,hdps_id
                                   ,server_id
                                   ,os_id                
                                   ,dwdm_id           
                                   ,extender_id           
                                   ,switch_id           
                                   ,interface_id           
                                   ,hur_id                
                                   ,storage_family_id
select distinct
     a.hdlm_id           
               ,b.multipath_id           
               ,c.true_copy_id           
               ,d.uvm_id                
               ,e.tuning_id           
               ,f.cluster_id           
               ,g.middleware_id
               ,h.tape_id
               ,i.third_party_id
               ,j.nas_id
               ,k.hba_id
               ,l.bcm_id
               ,m.volume_migration_version_id
               ,n.tiered_sto_mgr_version_id
               ,o.hdps_id
               ,p.server_id
               ,q.os_id                
               ,r.dwdm_id           
               ,s.extender_id           
               ,t.switch_id           
               ,u.interface_id           
               ,v.hur_id                
               ,w.storage_family_id
     from (select hdlm_id from all_prod_comb_tmp) a
,(select multipath_id from all_prod_comb_tmp) b
,(select true_copy_id from all_prod_comb_tmp) c
               ,(select uvm_id from all_prod_comb_tmp) d
               ,(select tuning_id from all_prod_comb_tmp) e
               ,(select cluster_id from all_prod_comb_tmp) f
               ,(select middleware_id from all_prod_comb_tmp) g
               ,(select tape_id from all_prod_comb_tmp) h
               ,(select third_party_id from all_prod_comb_tmp) i
               ,(select nas_id from all_prod_comb_tmp) j
               ,(select hba_id from all_prod_comb_tmp) k
               ,(select bcm_id from all_prod_comb_tmp) l
               ,(select volume_migration_version_id from all_prod_comb_tmp) m
               ,(select tiered_sto_mgr_version_id from all_prod_comb_tmp) n
               ,(select hdps_id from all_prod_comb_tmp) o
               ,(select server_id from all_prod_comb_tmp) p
               ,(select os_id from all_prod_comb_tmp) q
               ,(select dwdm_id from all_prod_comb_tmp) r
               ,(select extender_id from all_prod_comb_tmp) s
               ,(select switch_id from all_prod_comb_tmp) t
               ,(select interface_id from all_prod_comb_tmp) u
               ,(select hur_id from all_prod_comb_tmp) v
               ,(select storage_family_id from all_prod_comb_tmp) w;
But after looking at the explain plan we had to discard this. Simply not possible. Please help us with some other feasible solution.
regards,
Dipankar Kushari.

Hi,
That's what I have written while posting. Cartesian is no way possible. But is there any way so that I can find out all possible combination of the following values which is there in a table.
1 HDLM_ID 377 586
2 MULTIPATH_ID 142 357
3 TRUE_COPY_ID 1 87 12
4 UVM_ID 89 79
5 TUNING_ID 10 9 8
6 CLUSTER_ID 3 327 638
7 MIDDLEWARE_ID
8 TAPE_ID 3 47 54
9 THIRD_PARTY_ID 3
10 NAS_ID 12 91 1
11 HBA_ID 300 400
12 BCM_ID 14
13 VOLUME_MIGRATION_VERSION_ID 13 12
14 TIERED_STO_MGR_VERSION_ID 1 2
15 HDPS_ID 10 100
16 SERVER_ID 3 4
17 OS_ID 2 7
18 DWDM_ID 1
19 EXTENDER_ID 520
20 SWITCH_ID 4
21 INTERFACE_ID 2 1 3 4
22 HUR_ID 2 1 3 4 5
23 STORAGE_FAMILY_ID 2
regards,
Dipankar.

Similar Messages

  • All possible combinations of a column as applied to a unique entry?

    i am having trouble getting a loop to do what i want, if you
    can help me find out what i am doing wrong i would appreciate it:
    i have a database with 3 tables in it
    table 1 has a list of documents - each one having a primary
    key
    table 2 has a list of document properties, i will call them
    property A, B, and C - each one having a primary key
    table 3 is a "relational" table that has a column for a
    document's PK and a property's PK that that document has
    Example of table 3:
    docPK / propPK
    1 (Document 1) / 1 (A)
    2 (Document 2) / 1 (B)
    3 (Document 3) / 2 (B)
    1 (Document 1) / 2 (B)
    1 (Document 1) / 3 (C)
    i need to create a loop in ColdFusion that spits out the
    number of possible combinations that exist for each document
    so the correct output should look like:
    Property A
    Document 1
    Property B
    Document 1
    Document 2
    Document 3
    Property C
    Document 3
    Property A, Property B
    Document 1
    Proberty A, Property B, Property C
    Document 1
    this output displays all possible combinations of properties
    under the conditions of existing documents
    here is the loop i have so far that does not seem to be
    working for me,
    <cfoutput query="rsProperties">
    <ul>
    <cfloop from="0" to="# of properties per document"
    index="i">
    <li>
    <cfoutput group="propPK">
    <cfif i EQ "# of properties per document">
    [#Trim(propertyName)#]
    </cfif>
    </cfoutput>
    </li>
    <ul>
    <cfoutput group="docPK">
    <li><a href="">#Document
    Name#</a></li>
    </cfoutput>
    </ul>
    </cfloop>
    </ul>
    </cfoutput>
    my loop returns possible combinations, but it is not
    returning ALL possible combinations, for example it may only return
    Property A as a single instead of also returning singles Property B
    and C
    my query simply consists of a SELECT * FROM [the database]
    WHERE [the three tables are set equal (as a join)] AND WHERE
    [documents exist]
    i know this is all rather confusing but if you can help me
    make sense of it i will be grateful
    thanks for your time

    Read the cfoutput section of the cfml reference manual. If
    you don't have one, the internet does.
    Look for the example that shows you how to use the group
    attribute.

  • Generating all possible combinations question

    i'm trying to generate all possible combinations for several single column tables each with one string column.
    so - if table 1 has values (aa, ab, ac)
    table 2 has values (zz, zx)
    table 3 has values (qw, qe)
    the result set would contain all possible combinations:
    aa, ab, ac, zz, zx, qw, qe, aazz, aazx, aaqw, aaqe, aazzqw, aazzqe, aazxqw, aazxqe...etc.
    I've tried cross joins - but that does not get the smaller combinations.
    I've looked at some code examples but they seem to be focused on single letter or number combinations.
    I need to do this using tsql.
    code examples or links to such would be of much help.
    Thanks.

    Something like this might work:
    with t1 as (
    select val from table1
    union all
    select ''
    ), t2 as (
    select val from table2
    union all
    select ''
    , t3 as (
    Select val from table3
    union all
    select ''
    select t1.val + t2.val + t3.val
    from t1 cross join t2 cross join t3
    Russel Loski, MCT, MCSE Data Platform/Business Intelligence. Twitter: @sqlmovers; blog: www.sqlmovers.com

  • Printing all possible combinations of a given word.

    Well I'm supposed to print all possible combinations of a given word(I'm writing this for the benefit of those who might not have guessed this from the subject). I've got some code but its horribly wrong. Could anyone point out any mistakes.
    public class Try
        public void display(String s)
            char ch[]=s.toCharArray();
            for(int i=0;i<ch.length;i++)
                String word="";
                word+=ch;
    char c[]=new char[s.length()];
    for(int j=0;j<ch.length;j++)
    if(ch[j]!=ch[i])
    c[j]=ch[j];
    for(int j=0;j<ch.length;j++)
    for(int k=0;k<ch.length;k++)
    if(c[j]!=c[k])
    word+=c[k];
    word+=c[j];
    System.out.println(word);

    Me and Lucifer have been workin on this program for ages.... we cant quite understand your pseudo code.. could you elaborate a bit more on how it works ??
    Meanwhile this is the dysfunctional program weve managed to come up with so far:
    public class SHAM
        public void display(String s)
            char c[]=s.toCharArray();
            for(int i=0;i<c.length;i++)
                String word="";
                char c1[]=new char[c.length-1];
                int a=0;
                for(int l=0;l<c.length;l++)
                    if(i!=l)
                        c1[a++]=c[l];
                for(int j=0;j<c.length-1;j++)
                    char c2[]=c1;
                    word=c[i]+word;
                    if(j+1!=c.length)
                        char t=c2[j];
                        c2[j]=c2[c2.length-1];
                        c2[c2.length-1]=t;
                    for(int k=0;k<c2.length;k++)
                        word+=c2[k];
                    System.out.println(word);               
    }And this is my coding of your pseudo code:
    public class WordCombo2
        public void combo(String s)
            getCombos(s.toCharArray(), s.length());
        private void getCombos(char[] c,int n)
            if (n==1)
                print(c);
                System.out.println();
            else
                for (int i=0;i<c.length;i++)
                    if (i==0 && i<n)
                        c=c[n-1];
    n--;
    getCombos(c,n);
    c[i]=c[n-1];
    private void print(char c[])
    for (int i=0;i<c.length;i++)
    System.out.print(c[i]+" ");
    I really dont understand how this is supposed to work so i dont know whats wrong :( Im sorry this program is just totally baffling me, and on top of that recursion kind of confuses me.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Fill Array with all possible combinations of 0/1

    Hi,
    i'm looking for a fast way to fill an array, respectively an int[8], with all possible combinations of 0 and 1 (or -1 and 1, shouldn't make a difference).
    I kind of know how to do it using multiple loops but I assume there is a more elegant or at leaster "better" practice.
    Thanks,
    nikolaus
            static int cnt = 0;
         public static void main(String[] args) {
              int[] element = new int[]{1,1,1,1,1,1,1,1};
              Integer[] x = new Integer[2];
              x[0] = 1;
              x[1] = -1;
              for(int i7:x){
                   element[7] = i7;
                   for(int i6:x){
                        element[6] = i6;
                        for(int i5:x){
                             element[5] = i5;
                             for(int i4:x){
                                  element[4] = i4;
                                  for(int i3:x){
                                       element[3] = i3;
                                       for(int i2:x){
                                            element[2] = i2;
                                            for(int i1:x){
                                                 element[1] = i1;
                                                 for(int i0:x){
                                                      element[0] = i0;
                                                      cnt++;
              }Edited by: NikolausO on Oct 30, 2008 4:21 AM
    Edited by: NikolausO on Oct 30, 2008 4:22 AM

    pm_kirkham wrote:
    No I replied to message number 5. as the ' (In reply to #5 )' above my post indicates, which was in reply to (a reply) to Sabre150's post which wasn't using enhanced loops, nor has any obvious place where you could use that approach to fill the array.
    Though you could pass in an array of the values to fill the array with, and loop over those, instead of using 0 or 1, at which point Sabre's approach becomes the same as your OP, but without the manual unrolling:
    import java.util.Arrays;
    public class NaryCombinations {
    public interface CombinationHandler {
    void apply (int[] combination) ;
    public static void main(String[] args) {
    calculateCombinations(new int[]{-1, 0, 1}, 4, new CombinationHandler () {
    public void apply (int[] combination) {
    System.out.println(Arrays.toString(combination));
    public static void calculateCombinations (int[] values, int depth, CombinationHandler handler) {
    recursivelyCalculateCombinations(values, 0, depth, handler, new int[depth]);
    private static void recursivelyCalculateCombinations (int[] values, int index, int depth,
    CombinationHandler handler, int[] combination) {
    if (index == depth) {
    handler.apply(combination);
    } else {
    for (int value : values) {
    combination[index] = value;
    recursivelyCalculateCombinations(values, index + 1, depth, handler, combination);
    Which looks to use the same basic approach to the generalization I created shortly after posting the original.
    public class Scratch1
         * A 'callback' to be invoked with every combination
         * of the result.
        public interface Callback
             * Invoked for each combination.
             * <br>
             * Each call is passed an new instance of the array.
             * @param array the array containing a combination.
            void processArray(int[] array);
        public Scratch1(final int[] array, final Callback callback, final int... values)
            if (callback == null)
                throw new IllegalArgumentException("The 'callback' cannot be 'null'");
            if (array.length < 1)
                throw new IllegalArgumentException("The array length must be >= 1");
            if ((values == null) || (values.length < 1))
                throw new IllegalArgumentException("The 'values' must have be at least of length 2");
            callback_ = callback;
            values_ = values.clone();
            array_ = array;
        public Scratch1(final int order, final Callback callback, final int... values)
            this(new int[order], callback, values);
         * Generates every possible value and invokes the callback for each one.
        public void process()
            process(0);
         * Internal method with no logical external use.
        private void process(int n)
            if (n == array_.length)
                callback_.processArray(array_.clone());
            else
                for (int v : values_)
                    array_[n] = v;
                    process(n + 1);
        private final Callback callback_;
        private final int[] values_;
        private final int[] array_;
        public static void main(String[] args) throws Exception
            final Callback callback = new Callback()
                public void processArray(int[] array)
                    System.out.println(java.util.Arrays.toString(array));
            new Scratch1(6, callback, 2, 1, 0).process();

  • Creating a tree of all possible combinations of {a,b,c,d}

    I am an MSc conversion student who is struggling with the initial stages of coding his Association Rule Mining dissertation project.
    I have a TreeNode class, which is in the process of being written.
    The class is designed to create a tree that stores all possible combinations of a Vector alphabet of strings {a,b,c,d}
    Please could somebody explain what my TreeNode class is doing so far?
    I have had a lot of help with this and I can't understand why there are so many vectors and what they all do.
    A few pointers (no sarcastic comments please) would be much appreciated.
    The code so far:
    package treenode;
    import java.io.*;
    import java.util.*;
    public class TreeNode
    public static final String INFO_TEXT ="A program to store a vector of string items a,b,c,d in all their possible combinations into a TreeNode class";
    private Vector alphabet;
    private Vector data; // this IS TreeRootData
    private Vector children;
    public TreeNode(Vector inputAlphabet, Vector inputData)
    // the alphabet and data have already been parsed in.
    this.alphabet = inputAlphabet;
    this.data = inputData;
    System.out.println("Tree node constructed with data "+displayVectorOfStrings(this.data));
    children = new Vector(); // we now construct the Vector of children
    //createChildren();
    public void createChildren()
    if data.length =
    // first check to see whether the current data length is the same
    // as the length of the alphabet
    // if it is then stop here (return;)
    // we loop through the alphabet we have...
    // for each candidate in the alphabet, attempt to create a new child TreeNode
    // with a data Vector that is the same as the data in this TreeNode plus
    // the candidate we are looking at in the alphabet. i.e. add available LHS
    // NB: Do NOT add if the candidate is already in the data. {a,b,a} is wrong!
    // NB: We will check to see whether data is already in the tree at a later stage
    // NB: The new Child TreeNode MUST BE ADDED to the children VECTOR -
    // or it will be lost
    public static String displayVectorOfStrings(Vector vector) //Printing the Vector of Strings
    String vectorText = "{";
    for (int i=0; i<vector.size(); i++)
    vectorText += (String)vector.elementAt(i)+",";
    if (vector.size() > 0) vectorText = vectorText.substring(0, vectorText.length()-1);
    // now we chop off the last element, replacing it with a closing bracket,
    // provided that the Vector is not empty.
    vectorText += "}";
    return vectorText;
    public static void main(String[] args) //main method WITH THE ARGUMENTS PASSED IN.
    // This main class can be thought of as OUTSIDE the TreeNode class. Although
    // it is in the file called TreeNode.java it is only here for convenience.
    // This is the top level of the program where everything starts. It is here -
    // that the alphabet is hardcoded in and that the Tree root is constructed.
    displayHeading();
    Vector alphabet = new Vector(); // constructing an initial alphabet,
    alphabet.addElement("a"); // which will eventually come from the database
    alphabet.addElement("b");
    alphabet.addElement("c");
    alphabet.addElement("d");
    System.out.println("Alphabet set to be "+TreeNode.displayVectorOfStrings(alphabet));
    // the root's initial data is now made into an empty Vector...
    Vector initialData = new Vector();
    // the root can now be constructed
    TreeNode treeRoot = new TreeNode(alphabet, initialData); // the treeRoot constructor
    public static void displayHeading()
    System.out.println();
    System.out.println(INFO_TEXT);

    I don't remember from which site I took this material.
    You read this to find all possible combination of a set {a,b,c,d}
    Consider three elements A, B, and C. It turns out that for n distinct elements there are n! permutations possible. For these three elements all of the possible permutations are listed below:
    ABC, ACB, BAC, BCA, CAB, CBA
    Since there are 3 elements there are 3! = 6 permutations possible.
    Suppose instead of A, B, and C you have a deck of 52 playing cards. There are 52! permutations possible (i.e., the number of different ways the cards could be shuffled). Since 52! = 8x10^67, you will need to play a lot of cards before you have seen every permutation of the deck! Since shuffling the deck is a random process (or it should be), each of these 52! permutations is equally likely to occur.
    Developing a non-recursive algorithm to generate all permutations of n elements is a non-trivial task. However, developing a recursive algorithm to do this requires only modest effort and this is what we will do next.
    1. Let E = {e1, e2, ..., en } denote the set of n elements whose permutations we are to generate.
    2. Let Ei be the set obtained by removing element i from E.
    3. Let perm(X) denoted the permutations of the elements in the set X.
    4. Let ei.perm(X) denote the permutation list obtained by prefixing each permutation in perm(X) with element ei.
    Consider the following example, which is provided to clarify the definitions given above:
    If E = {a, b, c}, then E1 = {b, c} since the element in position 1 has been removed from E to create E1. Perm(E1) = (bc, cb) since these are the only two possible permutations of the two elements which appear in E1. Finally, e1.perm(E1) = (abc, acb) which should be apparent from the value of e1 and perm(E1) since the element a is simply used as a prefix to each permutation in perm(E1).
    Given these definitions, we set the recursion base case when n = 1. Since only one permutation is possible for one element, perm(E) = (e) where e is the lone element in E. When n > 1, perm(E) is the list e1.perm(E1) followed by e2.perm(E2) followed by e3.perm(E3) � followed by en.perm(En). This recursive definition of perm(E) defines perm(E) in terms of n perm(X)s, each of which involves an X with n � 1 elements. Thus both the base component and the recursive component (of a recursive algorithm) have been established and we thus have a complete recursive technique to generate the permutations.
    The following Java method is an implementation of this recursive definition of perm(E). This method will output all permutations whose prefix is list[0:k-1] and whose suffixes are the permutations of list[k:m]. By invoking the method with Perm(list, 0, n-1) all n! permutations of list[0: n-1] will be produced. [This is because this invocation will set k = 0 and m = n � 1, so the prefix of the generated permutations is null and their suffixes are the permutations of list[0: n-1]. When k = m, there is only one suffix which is list[m] and list[0: m] defines a permutation that is to be produced. When k < m, the else clause is executed.
    In the algorithm, let E denote the elements in list[k: m] and let Ei be the set obtained by removing ei = list[i] from E. The first swapping sequence in the for-loop has the effect of setting list[k] = ei and list[k+1: m] = Ei. Therefore, next statement which is the call to perm computes ei.perm(Ei). The final swapping sequence restores list[k: m] to its state prior to the first swapping sequence (the state is was in before the recursive call occurred).
    public static void perm(Object [] list, int k, int m)
    {    //generate all permutations of list[k:m]
    int i; Object temp;
    if (k == m) //list has one permutation � so output it
    {      for (i = 0; i <= m; i++)
    System.out.print(list);
    System.out.println;
    else //list has more than one permutation � so generate them recursively
    for (i = k; i <= m; i++)
    {     temp = list[k]; //these next three lines are a simple swap function
    list[k] = list[i];
    list[i] = temp;
    perm(list, k+1, m); //the recursive call
    temp = list[k]; //reset the order in the list
    list[k] = list[i];
    list[i] = temp;
    }//end for-loop
    } //end method perm
    See the program pasted below that prints all possible combination of a set {a,b,c,d}
    public class Perm
    public Perm()
    public static void main(String[] args)
    String s = "abcd";
    char [] chars = s.toCharArray();
    perm(chars, 0);
    public static void perm(char [] list, final int k)
    int i;
    char temp;
    if (k == list.length-1) //list has one permutation, so output it
    for (i = 0; i <= list.length-1; i++)
    System.out.print(list[i]);
    System.out.println();
    else { //list has more than one permutation, so generate them recursively
    for (i = k; i <= list.length-1; i++)
    temp = list[k]; //these next three lines are a simple swap function
    list[k] = list[i];
    list[i] = temp;
    perm(list, k+1); //the recursive call
    temp = list[k]; //reset the order in the list
    list[k] = list[i];
    list[i] = temp;
    }//end for-loop

  • Is it possible to insert a column break in table text?

    I have a bullet list--a Purchase Order checklist.
    Each list item is fairly short, so I designed the checklist with a two column format.
    I have implemented this in my LiveCycle form by breaking the checklist into two blocks of source text, each mapped to a table cell.
    However, my customer is unhappy with the idea of their text being broken into two pieces as it will display in their web UI as two pieces and they think this will be confusing. (Customers. Go figure.)
    Is there a character I can insert in the text to force a break so the text will flow to the next column in the table? I tried using a conditional break but that did not work as I can only specify content areas, not fields.
    Thanks,
    Janet

    holding the <option> key while typing return will insert a newline character in a cell

  • Combining the same column from 2 tables with distinct result.

    I have 2 tables with identical name columns. One is current people and the other is historical people. I want a select that returns any name that is in either table. I want each name listed only once. I want to see 1 entry for each name if it is in the current table, the historical table, or both tables. I can easily do a select distinct on each table but how do I join the queries to get 1 result set with no duplicates? The name column is not a key field and I don't want any other columns from either table.

    Just a simple UNION:
    select name
      from current
    union
    select name
      from historical;

  • Help with oracle sql to get all possible combinations in a table.

    Hello guys I have a small predicatement that has me a bit stumped. I have a table like the following.(This is a sample of my real table. I use this to explain since the original table has sensitive data.)
    CREATE TABLE TEST01(
    TUID VARCHAR2(50),
    FUND VARCHAR2(50),
    ORG  VARCHAR2(50));
    Insert into TEST01 (TUID,FUND,ORG) values ('9102416AB','1XXXXX','6XXXXX');
    Insert into TEST01 (TUID,FUND,ORG) values ('9102416CC','100000','67130');
    Insert into TEST01 (TUID,FUND,ORG) values ('955542224','1500XX','67150');
    Insert into TEST01 (TUID,FUND,ORG) values ('915522211','1000XX','67XXX');
    Insert into TEST01 (TUID,FUND,ORG) values ('566653456','xxxxxx','xxxxx');
    "TUID"                        "FUND"                        "ORG"                        
    "9102416AB"                   "1XXXXX"                      "6XXXXX"                     
    "9102416CC"                   "100000"                      "67130"                      
    "955542224"                   "1500XX"                      "67150"                      
    "915522211"                   "1000XX"                      "67XXX"                      
    "566653456"                   "xxxxxx"                      "xxxxx"                       The "X"'s are wild card elements*( I inherit this and i cannot change the table format)* i would like to make a query like the following
    select tuid from test01 where fund= '100000' and org= '67130'however what i really like to do is retrieve any records that have have those segements in them including 'X's
    in other words the expected output here would be
    "TUID"                        "FUND"                        "ORG"                        
    "9102416AB"                   "1XXXXX"                      "6XXXXX"                     
    "9102416CC"                   "100000"                      "67130"                      
    "915522211"                   "1000XX"                      "67XXX"                      
    "566653456"                   "xxxxxx"                      "xxxxx"  i have started to write a massive sql statement that would have like 12 like statement in it since i would have to compare the org and fund every possible way.
    This is where im headed. but im wondering if there is a better way.
    select * from test02
    where fund = '100000' and org = '67130'
    or fund like '1%' and org like '6%'
    or fund like '1%' and org like '67%'
    or fund like '1%' and org like '671%'
    or fund like '1%' and org like '6713%'
    or fund like '1%' and org like '67130'
    or fund like '10%' and org like '6%'...etc
    /*seems like there should be a better way..*/can anyone give me a hand coming up with this sql statement...

    mlov83 wrote:
    if i run this
    select tuid,fund, org
    from   test01
    where '100000' like translate(fund, 'xX','%%') and '67130' like translate(org, 'xX','%%');this is what i get
    "TUID"                        "FUND"                        "ORG"                        
    "9102416AB"                   "1XXXXX"                      "6XXXXX"                     
    "9102416CC"                   "100000"                      "67130"                      
    "915522211"                   "1000XX"                      "67XXX"                      
    "566653456"                   "xxxxxx"                      "xxxxx"                      
    "9148859fff"                  "1XXXXXX"                     "X6XXX"                       the last item should be excluded. The second digit in "org" is a "7" Fund is wrong, too. You're looking for 6 characters ('100000'), but fund on that row is 7 characters ('1XXXXXX').
    and this is sitll getting picked up.That's why you should use the _ wild-card, instead of %
    select  tuid, fund, org
    from    test01
    where  '100000' like translate (fund, 'xX', '__')
    and    '67130'  like translate (org,  'xX', '__')
    ;It's hard to see, but, in both calls to TRANSLATE, the 3rd argument is a string of 2 '_'s.

  • Getting a list of all months between 2 DATE columns for a table

    Current set:
    IF OBJECT_ID('tempdb..#TEST') IS NOT NULL
    DROP TABLE #TEST
    CREATE TABLE #TEST
    ID INT,
    DOB DATE,
    EffectiveDate DATE,
    TerminationDate DATE,
    GCode CHAR(1)
    INSERT INTO #TEST
    VALUES
    (1043,'1/1/1970','1/1/2014','4/1/2014','S'), -- Active in month Jan,Feb,March,April
    (1051,'1/1/1989','3/1/2014','5/1/2014','P'), -- Active in month March,April,May
    (1070,'1/1/2010','5/1/2014','8/1/2014','G') -- Active in month May,June,July,August
    SELECT * FROM #TEST
    Expected result set:
    ID          Month         GCode
    1043      January      S
    1043      February    S
    1043      March         S
    1043      April           S
    1051      March        P
    1051      April          P
    1051      May          P
    ---- Similarly for ID 1070
    This is needed for the reporting and each ID will have points associated to it, that will be a separate column that I'll be adding. The reason that I want this result set is because, the user might say, how many points did the ID have for a particular month.
    The points are not going to change for an ID. Please let me know how to get the expected result set

    Try
    -- code #1
    set LANGUAGE English;
    set dateformat MDY;
    declare @Month table (N int, T varchar(20));
    declare @I int, @D date;
    set @I= 1;
    set @D= '1/1/2014';
    while @I <= 12
    begin
    INSERT into @Month values (@I, DateName(month, @D));
    set @I+= 1;
    set @D= DateAdd(month, +1, @D);
    end;
    SELECT ID, T, GCode
    from @Month as M inner join
    #TEST as T on M.N between Month(EffectiveDate) and Month(TerminationDate)
    order by ID, N;
    José Diz     Belo Horizonte, MG - Brasil

  • Possible combination of coins

    Hello, I'm just new here. I have some algorithm problem with algorithm that couldn't put it to a code. The problem is "For a given denomination of money (5, 10, 20, 50, 100), get all possible combinations that will not exceed 2000 and at least one of them is present".
    I know this is easy for others but for me, it's quite difficult. I already searched but I can't find something that is similar with this problem.
    Here's what I tried,
    Given:
    denominations = { 5, 10, 20, 50, 100};
    total = 2000;
    A=5, B=10, C=20, D=50, E=100
    A' = counts of A // A' >= 1
    B' = counts of B // B' >= 1
    C' = counts of C // C' >= 1
    D' = counts of D // D' >= 1
    E' = counts of E // E' >= 1
    A A' + BB' + C*C' + D*D' + E*E' <= total
    The problem is I can't find a way for a possible counts of the denomination.
    Any help is much appreciated.
    Thanks.

    For a brute force approach, consider a simpler problem:
    Can you solve the problem if denominations = {5} and maxValue = 1820?
    For each solution of the problem the above case, does it generate a smaller problem to be solved for the next higher denomination in {5, 10, 20, 50, 100}?
    Can you see how to get a solution to the bigger problem from the smaller ones?
    If you've done data structures in your course, you may also want to make it more efficient by memotisation so you don't recompute the combinations of 20,50,100 given 10 = 2 * 5 etc.

  • Sort functionality using MULTIPLE columns in a table control

    Hi all,
    I have a custom screen with table control.Now i need to provide SORT functinality in this screen for the columns in the table control.
    My questins:
    1.Is it possible to seelct MULTIPLE columns in a table control for SORTING?If yes,what explicit settings do i need to do while creatng the TABEL CONTROL in the screen?DO I need to select "Column selection " as MULTIPLE??
    2.How do I write the code for SORT functinonality for multiple columns?
    I know how to write the code for SORTING on basis of single column .
    Thanks!

    Hi Rob,
    Thanks for the reply.
    However I was thinking to apply the same logic as for single columns as follows:
    types : begin of ty_fields,
                c_fieldname(20),
               end of ty_fields.
    data  : t_fields type table of ty_fields,
               wa_fields like line of t_fields.
    WHEN 'SORTUP'.(Ascending)
          loop at TABLE tc01-cols INTO wa_tc01  where  selected = 'X'.
          SPLIT wa_tc01-screen-name AT '-' INTO g_help g_fieldname.
          wa_fields-c_fieldname = g_fieldname.
          append wa_fields to t_fields.
          endloop.
          describe table t_fields lines l_index.
          c_count = 1.
          if c_count  <= l_index.
          read table t_fields into wa_fields index c_count.
          case c_count.
          when '1'.
          l_field1 = wa_fields-c_fieldname.
          when '2'.
         l_field2 = wa_fields-c_fieldname.
        and so on depending on the no of columns in the table control...
          endcase.
          endif.
          SORT t_tvbdpl_scr BY  l_fields1 l_fields 2......l_fieldn.
    Let me know if the above method will work!Also for the above method to work will the type of fields(columns on whihc sort function will be applied) matter???
    Thanks again for your time.

  • How to move a column within a table?

    Hi All!
    Is it possible in Oracle 9i to move a column within a table? For instance, I have a table
    ID1 ID2 ID3 SRC_ID1 SRC_ID2 SRC_ID3
    and I want to add one more column ID4. So, I can do it like this:
    ALTER TABLE MY_TABLE
    ADD ID4 NUMBER(18);
    In this case, the column will be added to end of the table but I want to move the column on the position after ID3. So, my question is, is it possible to move a column within a table? And if yes, how I can do it?.
    Any help will be appreciate.
    With best regards,
    Andrej Litowka.

    Hi,
    Actually speaking it makes no difference where a column is placed in the table. The select clause is the one that decides on how to display the data. But still if you want to store it next to a particular column then there are 2 options...
    1. Rename &lt;tname&gt; to &lt;tname_1&gt;;
    Create view &lt;tname&gt; as select &lt;cols&gt; from &lt;tname_1&gt;;
    The above option is useful in case of selects. In case of DMLs it will have to do a little more work by going and firing the same on the actual underlying table.
    2. Rename &lt;tname&gt; to &lt;tname_1&gt;;
    Create table &lt;tname&gt; (&lt;new col order with the new col&gt;);
    Insert into &lt;tname&gt; (select &lt;col order&gt; from &lt;tname_1&gt;);
    This option seems to be better than the first one.
    Hope this helps you.
    Regards,
    DJ

  • How to find the column name and table name with a value

    Hi All
    How to find the column name and table name with "Value".
    For Example i have value named "Srikkanth" This value will be stored in one table and in one column i we dont know the table how to find the table name and column name
    Any help is highly appricatable
    Thanks & Regards
    Srikkanth.M

    2 solutions by Michaels (the latter is 11g upwards only)...
    michaels>  var val varchar2(5)
    michaels>  exec :val := 'as'
    PL/SQL procedure successfully completed.
    michaels>  select distinct substr (:val, 1, 11) "Searchword",
                    substr (table_name, 1, 14) "Table",
                    substr (t.column_value.getstringval (), 1, 50) "Column/Value"
               from cols,
                    table
                       (xmlsequence
                           (dbms_xmlgen.getxmltype ('select ' || column_name
                                                    || ' from ' || table_name
                                                    || ' where upper('
                                                    || column_name
                                                    || ') like upper(''%' || :val
                                                    || '%'')'
                                                   ).extract ('ROWSET/ROW/*')
                       ) t
    --        where table_name in ('EMPLOYEES', 'JOB_HISTORY', 'DEPARTMENTS')
           order by "Table"or
    SQL> select table_name,
           column_name,
           :search_string search_string,
           result
      from cols,
           xmltable(('ora:view("'||table_name||'")/ROW/'||column_name||'[ora:contains(text(),"%'|| :search_string || '%") > 0]')
           columns result varchar2(10) path '.'
    where table_name in ('EMP', 'DEPT')
    TABLE_NAME           COLUMN_NAME          SEARCH_STRING        RESULT   
    DEPT                 DNAME                ES                   RESEARCH 
    DEPT                 DNAME                ES                   SALES    
    EMP                  ENAME                ES                   JONES    
    EMP                  ENAME                ES                   JAMES    
    EMP                  JOB                  ES                   SALESMAN 
    EMP                  JOB                  ES                   SALESMAN 
    EMP                  JOB                  ES                   SALESMAN 
    EMP                  JOB                  ES                   PRESIDENT
    EMP                  JOB                  ES                   SALESMAN 
    9 rows selected.

  • Adding a column in advanced table using personalizations

    Is it possible to add a column in advanced table using personalizations.
    If Yes , then i am not able get "Create Item" Icon on Advanced table Level personalizations . Can some one give reason? or there is any other way to create Item in Adavnce table.
    Thanks, Avaneesh

    The support for adding an item in advancedTable is supported from 11.5.10 CU3 onwards. But you can manually add an item in the personalization document and upload it and that should work. I had earlier provided the xml tags for doing that in one of threads and you should be able to find that in the forum. If you are not getting it I will search it for you. We supported the same way of addition using personalization in CU3 so manual addition in to the pers document should be fine for this requirement only.

Maybe you are looking for