SELECT with the combination of two columns query

I need the research to write a nested select statement that would achieve the following.
Support I have a table as follows
TestTable
Name: Age: country
Test1: 10: USA
Test2: 11: us.
Test3: 12: us.
Test4: 11: Canada
Test5: 12: Canada

Now, I want to select in the table above gives the following information.
Get all the names of people who do not belong to this combination (10:USA, 11:Canada, 12:Canada). The list can be huge.
The result should be
Test1:10:USA
Test1:12:USA

If it was a combination, I can write
Select * from TestTable
the age where <>10 and <>country Canada

Also, I can also do
Select * from TestTable
the age where NOT IN (10,11) and country NOT IN (USA, COUNTRY)
But I do have that he would give me a correct result.

sush_msn wrote:
Is there a way I can move the age and the country as a list on the query?

You asked the right question.

Three things you need to know:

(1) your test data cover all combinations. This is the most comprehensive test data:

create table test_table1 as
WITH AGES AS (
  SELECT LEVEL+10 AGE FROM DUAL CONNECT BY LEVEL <= 3
), COUNTRIES AS (
  SELECT 'USA' COUNTRY FROM DUAL
  UNION ALL
  SELECT 'CANADA' COUNTRY FROM DUAL
)
SELECT 'Test' || ROWNUM NAME, AGE, COUNTRY FROM AGES, COUNTRIES;

NAME                                                AGE COUNTRY
-------------------------------------------- ---------- -------
Test1                                                11 USA
Test2                                                11 CANADA
Test3                                                12 USA
Test4                                                12 CANADA
Test5                                                13 USA
Test6                                                13 CANADA

(2) now, here's the answer to your question. You can go back two or more values in an expression by putting parentheses around them.

SELECT * FROM TEST_TABLE1
WHERE (AGE, COUNTRY) NOT IN (
  (11, 'USA'),
  (12, 'CANADA')
);

NAME                                                AGE COUNTRY
-------------------------------------------- ---------- -------
Test2                                                11 CANADA
Test3                                                12 USA
Test5                                                13 USA
Test6                                                13 CANADA

That's what made the Etbin above, but he used a select instead of a list of values.

(3) can AGE or COUNTRY ever be NULL? You want to return the records that have NULL values in them? If so, you must use NOT EXISTS instead of NO po WARNING: Etbin code needs a bit of change: "where (age, country) = (t.age, t.country)" should be "where (age, country) = ((t.age, t.country)) '. You must always additional brackets on the right side.

Tags: Database

Similar Questions

  • The combination of two columns in a single

    Hi guys,.

    Is it possible for a query to combine two columns into one? For example, lets say I have the following query:

    SELECT ID, FIRST_NAME, LAST_NAME
    EMPLOYEES

    I want the output to have two columns: one that contains the ID and the other containing name followed by a space followed by LAST_NAME. I know how to do this outside the query using coldfusion, but it save me a lot of work if there is some way that the query could do for me.

    Yes but the operand of concatenation varies somewhat from a database
    management system to the other.

    In Oracle, it would look this IIRC.

    SELECT ID, FIRST_NAME. ' ' || LAST_NAME AS FULL_NAME
    EMPLOYEES

  • Load the rule with the data in two columns.

    I have a SQL Interface as the source of data for my rule to load but I have two columns of data, it is possible to load them into the same rule of load?

    Published by: user5170363 on June 4, 2010 18:51

    Published by: user5170363 on June 4, 2010 19:04

    This is in addition to what Glenn says.
    Generally, we will have two types of data files.
    If we have five dimensions.

    (1) in the first five columns of data files is the names of the members and the last column data.
    The mapping is like this:
    column contains the names of the members the deposited property is a corresponding dimension name
    column contains numbers the area of the given property.

    (1) in the foucolumns files first is the member names and you have one or more columns of data
    The mapping is like this:
    column contains the names of the members the deposited property is a corresponding dimension name
    column contains numbers the property field is the names of the members of the dimension remaining problems (level 0).

    Note: To provide the missing information from the dimension, you can use header definition in the rules file.

  • How to export data to excel that has 2 tables with the same number of columns and the column names?

    Hi everyone, yet once landed upward with a problem.

    After trying many things to myself, finally decided to post here...

    I created a form in form builder 6i in which clicking on a button, the data gets exported to the excel sheet.

    It works very well with a single table. The problem now is that I cannot do the same with 2 tables.

    Because the tables have the same number of columns and the columns names.

    Here are the 2 tables with column names:

    Table-1 (MONTHLY_PART_1) Table-2 (MONTHLY_PART_2)
    SL_NOSL_NO
    MODELMODEL
    END_DATEEND_DATE
    U-1U-1
    U-2U-2
    U-4U-4
    ..................
    ..................
    U-20U-20
    U-25U-25

    Given that the tables have the same column names, I get the following error :

    402 error at line 103, column 4

    required aliases in the SELECT list of the slider to avoid duplicate column names.

    So how to export data to excel that has 2 tables with the same number of columns and the column names?

    Should I paste the code? Should I publish this query in 'SQL and PL/SQL ' Forum?

    Help me with this please.

    Thank you.

    Wait a second... is this a kind of House of partitioning? Shouldn't it is a union of two tables instead a join?

    see you soon

  • How can we do a single element with the content of two clips

    How can we do a single element with the content of two clips

    You try to get a picture of image? In other words, that contained two visible clips at the same time? If you are, change the substantive item to you main plot and another tie on top using an edit connect to the battery. Select the top item. Activate the transform tool and resize and reposition the clamp if necessary.

    Russ

  • Can we synchronize permission selected with the settings of operating system Notifications BB10 for our Application.

    Steps to follow:
    BB10 device--> settings--> Notifications--> Applications--> [name of your application]--> all alerts [Toggle button]

    I have an obligation to check whether or not 'All alerts' is allowed through settings when the application is running. To check if we can synchronize permission selected with the settings of operating system Notifications BB10 for my application. How to get javascript code if alerts permission is on / off, while the application is running.

    I tried adding the blackberry.system function and tried to hasPermission (blackberry.push) also, I can't determine if permission is allow / prohibit... Please suggest how to get that.

    I don't see a WebWorks API for this. If I expected to be anywhere, it's here:
    https://developer.BlackBerry.com/HTML5/APIs/beta/BlackBerry.notification.html#jbo1385148829097

    But it seems that this API has not been fully implemented; It may be useful to connect a developer Issue Tracker JIRA to get this feature added.

    At the same time, there is this API of Cascades that looks like what you're looking for:
    https://developer.BlackBerry.com/native/reference/Cascades/bb__platform__notificationapplicationsett...

    Write an extension for this feature should allow you to access this feature:
    https://github.com/BlackBerry/WebWorks-community-APIs/tree/master/BB10-Cordova/template

    At the same time, a colleague is currently working on an extension that should open many features of Qt, and I think that the API above should be accessible through this extension. He must be released over the next week or two, so you can wait for that as well.

    EDIT: On this last point, see this extension which provides a mechanism for attaching in the majority of the Qt APIs.

    https://github.com/BlackBerry/WebWorks-community-APIs/tree/master/BB10-Cordova/QtBridge

  • How can I create a constraint on the combination of four columns...

    Dear Guru,

    I have a question... I created the table with columns like "CCode', 'Size1', 'Size2', 'Sch1', 'Sch2', 'Description', 'CCdate '.

    Here I wanted to create a unique constraint on the combination of four columns "CCode', 'Size1', 'Size2', 'Sch1', 'Sch2.

    My requirement is that I don't want to allow duplicate records in the table for the four columns only.

    for example: "CC123", 10, 25, S110, S250,.

    If the new record comes with the same data. Then, I do not want to insert this record.i want to get a constraint voilated error.

    How can I create a constraint on the combination of four columns...

    Pls help me on this issue...

    Kind regards

    Shitab...

    I suggested already here the syntax,

    ALTER table your_table

    Add constraint cons_name unique (col1, col2, col3, col4, col5);

    And don't call me 'Sir '.

    See you soon!

  • Starting from two data tables, how do you get the values in two columns using values in a column (values get col. If col. A is not null values and get the pass. B if col. A is null)?

    Two tables provided, how you retrieve the values in two columns using values in a column (the pass get values. If col. A is not null values and get the pass. B if col. A is null)?

    Guessing

    Select nvl (x.col_a, y.col_b) the_column

    from table_1 x,.

    table_2 y

    where x.pk = y.pk

    Concerning

    Etbin

  • Unable to set keyframes in the audio clip selected with the pen tool - can no longer see the volume control line after developing the clip. What could be the problem? This seems to be the problem on any project that I opened.

    Cannot set keyframes in the audio clip selected with the pen tool - cannot see even the line volume control more to set keyframes on having developed the clip. What could be the problem?  I use the first CC pro @.

    You can use the Ctrl key and then click with the regular selection tool, clicking with ctrl will make a new keyframe. in this way, have no need for the tools. CTRL has other great shortcuts that will stop you having to spend retouching pads tools too.

    If the automation keyframe line is missing, you can switch on and off in the menu sequence.

  • The Central handle on the rectangle isn't gone when I select with the black arrow (v) tool. See the bounding box and the edges is both. Dd intermediate anchor to go?

    The Central handle on the rectangle isn't gone when I select with the black arrow (v) tool. See the bounding box and the edges is both. Dd intermediate anchor to go?

    haggyabeken,

    I'm afraid that you have come across the Rectangle Live bug, which is limited to MAC versions starting from 10.7 and 10.8, but not 10.9 (Mavericks), see this thread linked below.

    https://forums.Adobe.com/thread/1595973

    Thus, a switch for the Mavericks with a reinstall might be the way to solve it here and now.

    To get around it, in each case, it is possible to develop direct Rectangles to get the normal old shaped rectangles or Pathfinder > unit, or use the scale tool.

    A more permanent way round that is to create normal old shaped rectangles, after running the free script created by Pawel, see this thread with download link:

    https://forums.Adobe.com/thread/1587587

  • White on white selection with the magic wand of refining

    I'm trying to remove the background of a picture of BW - one model posing in front of a white background.

    Select with the magic wand works fine except on the area where the light on the model wears the white skin. When I choose, I get the hand and the lower part of the arm (see below) but miss the box top, completely white. I tried all kinds of settings and also tried to increase the contrast with a brightness/contrast layer, but nothing I I understand allows me to keep the arm and remove the bottom with the arm.  FWIW, the image cannot be redone.

    How can I do? Thanks for any help.

    EdB

    fist copy.jpg

    Learn how masking... Also in white when mixed in a layer with the blending mode multiply does not change.  So, if you add a new layer on top of your image and set its blending mode to multiply. You will see your arm starts to show through. Add a maske layer to this layer and paint with black to show the lower arm of the layer by hiding the top layer on the arm area.

  • I need help with the control of two .swf in third.

    Hi, thanks for reading!

    I need help with the control of two .swf in third.

    I have a problem when I need to use a .swf in a digital signage solution, but were advised by the Legal Department, it cannot be changed in any way, I can not also have the source file blah blah blah. I pulled the .swfs on their site and I decompiled to see what I was up against.

    The main SWF that I need control is HCIC.swf and the problem is that it starts with a preloader, which, after the loading stops on a framework that requires user input to (button) on a play button, until the film will proceed and replay.

    What I've done so far is to create a SWF container, HCIC_container.swf, which will serve as a target for the HCIC.swf and I would like to send actionscript in the file, I am not allowed to edit.

    I managed to get done with help from someone on another forum. It is my hope that the following script just start HCIC.swf a framework after the preloader and button play and just play through.

    var container: MovieClip = createEmptyMovieClip ("container", getNextHighestDepth());
    var mcLoader:MovieClipLoader = new MovieClipLoader();
    mcLoader.addListener (this);
    mcLoader.loadClip ("MCIC.swf", container);

    function onLoadInit(mc:MovieClip) {}
    mc.gotoAndPlay (14);
    }

    But unfortunately it does not solve my problem. Because there is a media - controller.swf, which is charged by HCIC.swf who has orders, including the play button to start HCIC.swf.

    Here is a link to a .zip with all 3 files .swf file and all 3 .fla files.

    http://www.axiscc.com/temp/HCIC.zip

    What I have to do is to automatically start the HCIC.swf file, bypassing the pre-loader and play button without having to edit it or in the media - controller.swf in any case. Thus, all scripts must be done in HCIC_container.swf.

    I know it is confusing and it is difficult to explain, but if you look at the files it must make sense.

    ActionScripting is far from my point hard, so I'm definitely over my head here.

    Thanks for your help.

    Got my solution on another forum.

    http://www.ActionScript.org/forums/showthread.php3?t=146827

  • selection of lines corresponding to two columns with two entry tables

    I have a table with two columns int primary key tab1. id1 and id2.

    Now I have two created two tables of figures: array1 {1, 2, 3,...} and {0, 1, 0,...} array2 Arrays have the same length.

    I want to do a select:
    Select * from tab1 where tab1.id1 = array1.column_value and tab1.id2 = array2.column_value;

    If I want to receive 13 lines with this request, I had 169 because it tries to match all the different combinations in the tables.

    If I do it with a loop for:

    for i of array1
    loop
    Select * from tab1 where tab1.id1 = array1 (i) and tab1.id2 (i);
    end

    That should illustrate what I want to do, I just thought it would be faster if I could do it without a loop, do not use the pl/sql. Can it be done? If not, should I use a loop for with bulk collect somehow?
    SQL> with t as (
      select 1 id1, 0 id2 from dual union all
      select 2, 0 from dual union all
      select 3, 0 from dual union all
      select 4, 1 from dual
    )
    --
    --
    select id1, id2
    from t,
         (select rownum rn1, a1.* from table (sys.odcinumberlist (1, 2, 3, 4)) a1) a1, --- array1
         (select rownum rn2, a2.* from table (sys.odcinumberlist (0, 1, 0, 1)) a2) a2  --- array2
    where (id1, id2) in ( (a1.column_value, a2.column_value)) and rn1 = rn2
    /
           ID1        ID2
    ---------- ----------
             1          0
             3          0
             4          1
    
    3 rows selected.
    
  • Select only the lines with the duplicate data in columns

    Hello

    I try to find roles here in duplication.  I created a script for me the employee, the name of the State, the title of the post, the end date and the union_id.

    Select
    p.emp_no,
    p.Surname | «, » || p.Forenames,
    p.person_status,
    j.job_title,
    j.end_date,
    j.union_id

    person p
    inner join appointee_history ah on trim (ah.emp_no) = trim (p.emp_no) and ah.change_date = (select max (change_date) in the appointee_history where ah.emp_no = emp_no)
    join in-house job j on trim (j.job_title) = trim (ah.job_title) and trim (j.org_unit) = trim (ah.org_unit)
    where j.change_date = (select max (j2.change_date) of j2 work
    where trim (j2.job_title) = trim (j.job_title) and trim (j.org_unit) = trim (j2.org_unit))

    and p.person_status like 'a % '.
    and p.emp_no not like 9% '
    and j.union_id is not null
    order of j.union_id

    However, I'm looking only for duplication through the union_id. I tried a having count (*) > 1 but the emp_no is configured to be separate, and I get and not a single - group function error.

    Can anyone recommend a way to do this please?   I would be very grateful.

    Hello

    2729819 wrote:

    ...  So the expected results.

    See you soon

    This is what produces the query I posted earlier, if you use the new table and the columns and (unlike me) come out MORE correctly:

    WITH got_cnt AS

    (

    SELECT emp_no

    person_status

    function

    union_id

    COUNT AS NTC (*) OVER (PARTITION BY union_id)

    SAMPLE

    )

    SELECT person_status, emp_no, union_id, function

    OF got_cnt

    WHERE cnt > 1

    ORDER BY union_id

    ;

    You can get the same results with the COUNT aggregate function, but it should be faster, because it requires only a single pass through the table.

  • Fill two empty columns with the values in a column (all in the same table)

    Can someone point me in the right direction? I want to fill the column prefix and suffix with the AcctNum data.

    "Prefix is the part of the number before the '-' and the suffix is everything after the '-'. '. Write a SQL command to fill the column prefix and suffix.
    *Accounts* 
    
    AcctNum   Prefix   Suffix
    -------   ------   -------
    123-0097
    X089-056
    123-0097
    123-0098
    F3377-D
    X089-057
    X089-058
    3-009712
    It is supposed to look like this:
    *Accounts* 
    
    AcctNum   Prefix   Suffix
    -------   ------   -------
    123-0097    123     0097
    X089-056
    123-0097
    123-0098
    F3377-D
    X089-057
    X089-058
    3-009712
    That's what I came with, but it does not work because it is basically putting multiple values into a single cell:
    update accounts
         set prefix=(select substr(acctnum, 1, instr(acctnum,'-')-1) from accounts),
         suffix=(select substr(acctnum, instr(acctnum, '-')+1) from accounts)
         where acctnum=(select prefix||'-'||suffix from accounts);
    I want this query is incredibly easy and I have forget something. Any help is greatly appreciated.

    Published by: 885913 on September 18, 2011 12:53
    UPDATE accounts a
    SET    ( prefix, suffix ) = (SELECT Substr(acctnum, 1, Instr(acctnum, '-') - 1),
                                        Substr(acctnum, Instr(acctnum, '-') + 1)
                                 FROM   accounts b
                                 WHERE  a.acctnum = b.acctnum);
    

Maybe you are looking for