How to select rows based on values from other table?

I need to select all rows from TABLE1 whose time column is NOT between fromTime and toTime from TABLE2.
For example, those table contain following rows:
TABLE1
|id |time |...
|1 | 10 |...
|2 | 20 |...
|... | ... |...
TABLE2
|fromTime|toTime|
| 3 | 6 |
| 10 | 16 |
| 20 | 25 |
So, in the case above the first and second rows shouldn't be returned by the query since 10<=10<=16 AND 20<=20<25.

Try
-- code #1
SELECT id, time
from TABLE1 as T1
where not exists (SELECT * from TABLE2 as T2
where T1.time between T2.fromTime and T2.toTime);
José Diz     Belo Horizonte, MG - Brasil

Similar Messages

  • Deleting rows from table based on value from other table

    Hello Members,
    I am struck to solve the issue said below using query. Would appreciate any suggestions...
    I have two tables having same structures. I want to delete the rows from TableA ( master table ) with the values from TableB ( subset of TableA). The idea is to remove the duplicate values from tableA. The data to be removed are present in TableB. Catch here is TableB holds one row less than TableA, for example
    Table A
    Name Value
    Test 1
    Test 1
    Test 1
    Hello 2
    Good 3
    TableB
    Name Value
    Test 1
    Test 1
    The goal here is to remove the two entries from TableB ('Test') from TableA, finally leaving TableA as
    Table A
    Name Value
    Test 1
    Hello 2
    Good 3
    I tried below queries
    1. delete from TestA a where rowid = any (select rowid from TESTA b where b.Name = a.Name and a.Name in ( select Name from TestB ));
    Any suggestions..
    We need TableB. The problem I mentioned above is part of process. TableB contains the duplicate values which should be deleted from TableA. So that we know what all values we have deleted from TableA. On deleted TableA if I later insert the value from TableB I should be getting the original TableA...
    Thanks in advance

    drop table table_a;
    drop table table_b;
    create table  table_b as
    select 'Test' name, 1 value from dual union all
    select 'Test' ,1 from dual;
    create table table_a as
    select 'Test' name, 1 value from dual union all
    select 'Test' ,1 from dual union all
    select 'Test' ,1 from dual union all
    select 'Hello' ,2 from dual union all
    select 'Good', 3 from dual;
    /* Formatted on 11/23/2011 1:53:12 PM (QP5 v5.149.1003.31008) */
    DELETE FROM table_a
          WHERE ROWID IN (SELECT rid
                            FROM (SELECT ROWID rid,
                                         ROW_NUMBER ()
                                         OVER (PARTITION BY name, VALUE
                                               ORDER BY NULL)
                                            rn
                                    FROM table_a a
                                   WHERE EXISTS
                                            (SELECT 1
                                               FROM table_b b
                                              WHERE a.name = b.name
                                                    AND a.VALUE = b.VALUE))
                           WHERE rn > 1);
    select * from table_a
    NAME     VALUE
    Test     1
    Hello     2
    Good     3Edited by: pollywog on Nov 23, 2011 1:55 PM

  • Update table based on values from other table

    Hi,
    I am trying to update one table based on the values of another table. Since you can't use From in update statements, how do you execute this?
    For example i have to tables, Table A and Table B. I want to update a column or columns in Table A based on another value in Table B:
    So if the column in Table B was 1 then column in Table A would be Yes, if Table B was 2, then Table A would be Yes, if Table B was 3 then Table A would be N/A and so on...
    Any help would be appreciated.
    thanks,
    scott

    SQL> select * from t1;
    ID ST
    1
    2
    3
    SQL> select * from t2;
    NO
    1
    2
    3
    4
    SQL> update t1 set status=(select decode(no,1,'Y',2,'N','NA') from t2 where t1.id=t2.no);
    3 rows updated.
    SQL> select * from t1;
    ID ST
    1 Y
    2 N
    3 NA
    Daljit Singh

  • Select LOV based on value in another table

    Hi all,
    I have an issue,
    I have an item with Select list with dynamic query in the dropdown ListofValues.
    but i want to use a condition like
    select val1 display_value val2 return_value
    from table2
    where value_in_table1 = username AND table_id1=table_id2
    in these two tables i have the id's common and table 1 is having the usernames.
    Can somebody help me in solving this issue please.
    Thanks in advance

    As far as I know, you can't dump PL/SQL into the list of values definition. Try just having select distinct PJT_NAME display_value, PROJECT_ID return_value from EZS_PROJECTS WHERE EMP_ID = :P1_XYZ ORDER BY 1

  • How to return the same SUM value from two tables

    Hello,
    I have the following data:
    SQL> SELECT * FROM t1;
         T1_ID   T1_VALUE
             1        500
             1        500
    SQL> SELECT * FROM t2;
         T2_ID   T2_VALUE
             1       1000
    SQL> SELECT t1_id, SUM(t1_value), SUM(t2_value)
      2    FROM t1, t2
      3   WHERE t1_id = t2_id
      4   GROUP BY t1_id;
         T1_ID SUM(T1_VALUE) SUM(T2_VALUE)
             1          1000          2000How is it possible that SUM(T2_VALUE) returns also 1000.
    Thank you

    Here's one way:
    with t1 as (select 1 t1_id, 500 t1_value from dual union all
                select 1 t1_id, 500 t1_value from dual),
         t2 as (select 1 t2_id, 1000 t2_value from dual)
    select t3.t3_id, t3.t3_sum, t4.t4_sum
    from   (select t1_id t3_id, sum(t1_value) t3_sum from t1
            group by t1_id) t3,
           (select t2_id t4_id, sum(t2_value) t4_sum from t2
            group by t2_id) t4
    where  t3.t3_id = t4.t4_id

  • How to select rows with min value on a specific column

    I have a query:
    select
      m.x1,
      round (to_date (l.y1, 'mm/dd/yyyy HH:MI:SS AM') - m.x2, 0) as numofdays
    from
      table1 m,
      table2 l
    where
      l.x3 = m.x3 and
      to_date (l.y1, 'mm/dd/yyyy HH:MI:SS AM') >= TO_DATE('01012013','MMDDYYYY') and
    and I got this result table:
    x1 (ID)
    numofdays
    001
    5
    001
    10
    002
    2
    003
    3
    003
    1
    004
    0
    005
    66
    several ID's have multiple values on the second column, I want to have only distinct IDs with smallest "numofdays" like this:
    x1 (ID)
    numofdays
    001
    5
    002
    2
    003
    1
    004
    0
    005
    66
    Any ideas?

    Hi,
    The most general and versatile way is a Top-N Query:
    WITH   got_r_num AS
        select
                m.x1,
                round (to_date (l.y1, 'mm/dd/yyyy HH:MI:SS AM') - m.x2, 0) as numofdays
        ,       ROW_NUMBER () OVER ( PARTITION BY  m.x1
                                     ORDER BY      to_date (l.y1, 'mm/dd/yyyy HH:MI:SS AM') - m.x2
                                   )  AS r_num
        from 
              table1 m,
              table2 l
        where
              l.x3 = m.x3 and
              to_date (l.y1, 'mm/dd/yyyy HH:MI:SS AM') >= TO_DATE('01012013','MMDDYYYY') and
    SELECT  x1, numofdays
    FROM    got_r_num
    WHERE   r_num   = 1
    If you'd care to post CREATE TABLE and INSERT statements for your sample data, then I could test it.
    Notice that the sub-query (got_r_num) is exactly what you posted, only with a new column (r_num) added to the SELECT clause.

  • Count MySQL rows based off Value in Dynamic Table

    Greetings all. I have 2 MySQL tables; 1 that contains the names of my classes.(Class A, Class, B, etc.) and 1 table that contains the names of students in each Class (for example Class A: John Doe; Class A: Susie Smith.; Class B: Jane Doe). In the 2nd table the Class name is in its own column and the student's name is in a 2nd column.
    I currently have a dynamic repeating table that lists the names of all of the classes from the 1st table. What I'm trying to do is add a second column to this repeating dynamic table that lists the number of students in each class. For example; Row 1 of the dynamic table would say "Class A | 5; Class B | 3; Class C | 7, etc.). The dynamic table works perfectly to list the class names. For the life of me I can't figure out how to perform a count for each class to insert in the repeating table. I will be adding more Classes which as why I'm trying to set up the counting query dynamically. So far I have only been able to figure out how to count the total rows in the 2nd table, or count the rows with a specified class name. Any advice or guidance on how to count the number of rows in the 2nd MySQL table based off the class name in the repeating table is much appreciated. Thank you for any and all help. Have a great day.

    Select count(*), Class from MyTable
    Group by Class
    Time to learn about SQL:
    http://www.w3schools.com/sql/sql_intro.asp

  • How to get multipe data set values from Decision Table.

    Hi All,
    I need to use SAP BRM for one of the scenario where based one some Code Group I need to get a set of questions and for each question a set of possible answers.
    The structure of Decision Table will be like below :
    Table 1 : To get set of questions based on Project Code
    Input                   Output           Output
    Project Code
    Question Id
    Question Description
    Table 2 : To get set of answers based on question
    Input                   Output            Output
    Question ID
    Answer Id
    Answer Description
    I already searched in forum to get the multiple values based on some input and that works fine for a single field with multiple outcome.
    Handling Selective Multiple Actions in  SAP Business Rules Management System
    In my scenario I need to get a set of Id and description as multiple outcome.
    Can anyone please let me know how this can be achieved in BRM.
    Thanks in advance
    Ravindra

    Create an XSD in the BRM project with the desired data structure and import the XSD alias in the 'Project Resources'. Add this XSD alias as input/output of the decision table.
    Refer this:
    Creating a Simple BRM Ruleset in 30 Easy Steps using NWDS 7.3 (Flow Ruleset with a Decision Table)

  • How to get all the column values from a table source

    Hi,
    I have created one table source on a employee table and some customized attributes using global settings>search attributes.
    Now these customized attributes mapped with the table columns through attribute mapping from the sorce tab.
    Using doOracleSearch method i passed last parameter i.e. Integer array of customized attributes.
    After execution of doOracleSearch method i am getting the results but customized attributes are not coming.
    getCustomAttributes method returns null instead of some values.
    Please refer following code for more info:
    Integer[] fetchAttr=new Integer[2];
    fetchAttr[0]=new Integer(137);
    fetchAttr[1]=new Integer(138);
    result =
    stub.doOracleSearch("BTM",
    new Integer(1),
    new Integer(10),
    Boolean.TRUE,
    Boolean.TRUE,
    group,
    "en",
    "en",
    Boolean.TRUE,
    null,
    null,
    fetchAttr);
    ResultElement[] resElements = result.getResultElements();
    for(int i = 0; i < resElements.length; i++)
    System.out.println("Title : " + resElements[0].getTitle());
    System.out.println("Snippet : " + resElements[0].getSnippet());
    System.out.println("URL : " + resElements[0].getUrl());
    System.out.println("non default : " + resElements[0].getCustomAttributes()); // it returns null here
    }

    Confirm the attributes you are asking SES for match those on the data source being searched. One thing to try is to simply tell SES to return all custom attributes for your search. Here is a snippet to build a list of all attribute IDs and pass them to your search...
    // Create and set SOAP URL
    OracleSearchService searchService = new OracleSearchService();
    searchService.setSoapURL("http://myserver:7777/search/query/OracleSearch");
    // Set attributes to fetch (all)
    Attribute[] attributesAll = searchService.getAllAttributes("en");
    ArrayList<Integer> attributeIds = new ArrayList<Integer>();
    for(Attribute a: attributesAll)
    attributeIds.add(a.getId());
    Integer attributeIdArrayAll[] = new Integer[attributeIds.size()];
    attributeIdArrayAll = attributeIds.toArray(attributeIdArrayAll);      
    // Query
    OracleSearchResult result = searchService.doOracleSearch("some text", ..........[other params], attributeIdArrayAll);
    // Print out results
    ResultElement[] resElements = result.getResultElements();
    for(int i = 0; i < resElements.length; i++)
    // Get document
    ResultElement doc = resElements;
    // Print Title
    System.out.println("Title: " + doc.getTitle());
    // Print custom attributes
    CustomAttribute[] attributes = doc.getCustomAttributes();
    for(int j = 0; j < attributes.length; j++)
    CustomAttribute attr = attributes[j];
         System.out.println("[Custom Attribute] " + attr.getName() + ": " + attr.getValue());
    Hope this helps.

  • How to select distinct values from a table when it has composite primary ke

    Hi
    I have the requirement like , I need to select distinct one column values from the table which has composite primary key. How to acheive this functioinality using view object.
    Eg : Table 1 has col1 and col2, col3
    col1 col2 col3
    1 A NA
    1 B NA
    2 A NA
    3 C NA
    2 D NA
    primary key (col1,col2)
    I have to select distinct col1.
    Thanks

    Hi
    I got the solution for above. By Creating the read only view object we can acheive this.
    thanks

  • Executed  Step outcome  value  from the table

    Hi,
       How to get the Step outcome  value  from the table for the executed workitem.
    Regards,
    Rani.

    Hi Rani,
    For database tables you can refer to tables:
    SWWLOGHIST -      History of a work item
    SWWORGTASK -      Assignment of WIs to Org.Units and Tasks
    SWWUSERWI -      Current Work Items Assigned to a User
    SWWWIHEAD -      Header Table for all Work Item Types
    SWWWIAGENT -      Gets agents assigned to a workitem
    You can you FMs like SAP_WAPI_GET_WORKITEM_DETAIL, SAP_WAPI_CREATE_WORKLIST as per your requirement.
    Hope this helps!
    Regards,
    Saumya

  • Decode from other table?

    how can i decode a column value from another table? e.g. the view selects an ID from TABLE1 and wants to add a column "Description" that decodes the value of the ID column. The decode() function is usable for a small set of fixed decodings. But what if the decoded values are not fixed and are stored in another table? Is it possible to write such a SELECT statement that decodes values with values from another table (instead of a fixed parameter list9?

    Are you looking for something like this:
    SQL> SELECT e.deptno,
      2         e.ename,
      3         (SELECT dname FROM scott.dept d WHERE d.deptno = e.deptno) description
      4  FROM   scott.emp e;
        DEPTNO ENAME      DESCRIPTION
            20 SMITH      RESEARCH
            30 ALLEN      SALES
            30 WARD       SALES
            20 JONES      RESEARCH
            30 MARTIN     SALES
            30 BLAKE      SALES
            10 CLARK      ACCOUNTING
            20 SCOTT      RESEARCH
            10 KING       ACCOUNTING
            30 TURNER     SALES
            20 ADAMS      RESEARCH
            30 JAMES      SALES
            20 FORD       RESEARCH
            10 MILLER     ACCOUNTING
    14 rows selected.
    SQL> disconnect
    Disconnected from Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.3.0 - Production
    SQL>

  • How to create a new row for a VO based on values from another VO?

    Hi, experts.
    in jdev 11.1.2.3,
    How to create a new row for VO1 based on values from another VO2 in the same page?
    and in my use case it's preferable to do this from the UI rather than from business logic layer(EO).
    Also I have read Frank Nimphius' following blog,but in his example the source VO and the destination VO are the same.
    How-to declaratively create new table rows based on existing row content (20-NOV-2008)
    http://www.oracle.com/technetwork/developer-tools/adf/learnmore/13-create-with-params-169140.pdf
    I have tried:
    1.VO1(id,amount,remark1) and VO2(id,amount,remark2) are based on different EO,but render in same page,
    2.Drag and drop a Createwithparams button for VO1(id,amount,remark),
    3.add: Create insertinside Createwithparams->Nameddata(amount),
    4.set NDName:amount, NDValue:#{bindings.VO2.children.Amount}, NDtype:oracle.jbo.domain.Number.
    On running,when press button Createwithparams, cannot create a new row for VO1, and get error msg:
    <Utils> <buildFacesMessage> ADF: Adding the following JSF error message: For input string: "Amount"
    java.lang.NumberFormatException: For input string: "Amount"
         at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
    Can anyone give some suggestions?
    Thanks in advance.
    bao
    Edited by: user6715237 on 2013-4-19 下午9:29

    Hi,CM,
    I'm really very appreciated for your quick reply! You know, today is Saturday, it's not a day for everyone at work.
    My principal requirement is as follows:
    1.select/check some rows from VO2, and for each selection create a new row with some attributes from VO2 as default values for VO1's corresponding attributes, and during this process the user may be cancel/uncheck or redo some of the selections.
    --so it's better to implement it in UI rather than in EO.
    2.it's better to implement this function with declarative way as in Frank Nimphius' blog.
    --little Jave/JS coding, the better. I only have experience in ORACLE FORMS, little experience in JAVA/JS.
    In order to get full information for the requirements of my use case, can take a check at:
    How to set default value for a VO query bind variable in a jspx page?
    (the end half of the thread: I have a more realworld requirement similar to the above requirement is:
    Manage bank transactions for clients. and give invoices to clients according to their transaction records. One invoice can contain one or many transactions records. and one transaction records can be split into many invoices.
    Regards
    bao
    Edited by: user6715237 on 2013-4-19 下午11:18
    JAVE->JAVA

  • How to get edited row values from ADF table?

    JDev 11.
    I have a table which is populated with data from Bean.
    I need to save changes after user make changes in any table cell. InputText is defined for table column component.
    I have defined ValueChangeListener for inputText field and AutoSubmit=true. So when user change value in inputText field, method is called:
    public void SaveMaterial(ValueChangeEvent valueChangeEvent) {
    getSelectedRow();
    SaveMaterial(material);
    This method should call getSelectedRow which take values from selected table row and save them into object:
    private Row getSelectedRow(){
    RichTable table = this.getMaterialTable();
    Iterator selection = table.getSelectedRowKeys().iterator();
    while (selection.hasNext())
    Object key = selection.next();
    table.setRowKey(key);
    Object o = table.getRowData();
    material = (MATERIAL) o;
    System.out.println("Selected Material Desc = "+material.getEnumb());
    return null;
    Problem is that getSelectedRow method doesnt get new (edited) values, old values are still used.
    I have tried to use ActiveButton with same method and it works fine in that case. New values are selected from active row and inserted into object.
    JSF:
    <af:table var="row" rowSelection="single" columnSelection="single"
    value="#{ManageWO.material}" binding="#{ManageWO.materialTable}">
    <af:column sortable="false" headerText="E-number">
    <af:inputText value="#{row.enumb}" valueChangeListener="#{ManageWO.SaveMaterial}" autoSubmit="true"/>
    </af:column>
    <af:column sortable="false" headerText="Description">
    <af:inputText value="#{row.desc}" valueChangeListener="#{ManageWO.SaveMaterial}" autoSubmit="true"/>
    </af:column>
    </af:table>
    <af:activeCommandToolbarButton text="Save" action="#{ManageWO.EditData}"/>
    What is a correct place from where save method should be called to get new (edited) values from ADF table?
    Thanks.

    Did you look into the valueChangeEvent?
    It has oldValue and newValue attributes.
    public void SaveMaterial(ValueChangeEvent valueChangeEvent) {
    Object oldVal = valueChangeEvent.getOldValue();
    Object newVal = valueChangeEvent.getNewValue();
    // check if you see what you are looking for.....
    getSelectedRow();
    SaveMaterial(material);
    }Timo

  • How to make validation in Bean and select value from another table

    I want to know how to select data from table in backing bean according to primary key i have
    the problem is that
    i have a table Employee_Salary contains Employee ids and their salary
    Empoloyee_Salary table
         Employee_ID      Number
         Employee_salary Number
    And Another table Called Employees
    Employees table
         Employee_ID     Number
         IsManager Varchar2 its value is [*Yes or NO*]
    and other columns that i don't care about this table
    i have on a jsff page an <af:table> this table is editable this is the Empoloyee_Salary table
    *i want to check before save or after insert if this employee is Manager [from Employees tabke(yes or no)] the salary*
    cannot be less that 100
    i want to know how to make this how to select the value from employees table according to the id i have in the employee_salary table how to make this and make this validation
    i have to select IsManager from Employees Table to see if this manager or no
    i want to know how to make this in a bean
    i use jdeveloper 11g
    and my project is ADF Fusion project
    and the page that have the Emplpyee_Salary table is JSFF
    thanks in advance

    You might want to write this code in a validator on the entity object if it should apply from every screen.
    If you want to access view objects from a backing bean the basics are here: http://download.oracle.com/docs/cd/E15523_01/web.1111/b31974/bcservices.htm#sthref918

Maybe you are looking for

  • My iPod 5th gen won't turn on!

    My iPod 5th gen was working fine last night and after charging it won't turn on with power button today. I'm not able to reboot using home button and power button simultaneously because my home button stopped working couple weeks back and I was using

  • ADF in JDeveloper 10.1.3.0.4: Error deploying bc4j.ear in JBoss-4.0.4.CR2

    Hello, Using the ADF Runtime Installer for JBoss found in JDeveloper 10.1.3.0.4, i've received deployment error during startup of JBoss. The error message as displayed in the console window as follows: 09:29:16,325 ERROR [URLDeploymentScanner] Incomp

  • Error while uploading Bank Statement using FF_5 with Multi Cash Option

    Hi I am trying to upload the Bank Statement in FF_5 screen with Multicash (MC) option and am facing the information message that Account XXXX  YYYY EUR : Statement 201100059 is not in the bank data storage. This is for the Germany Country Company Cod

  • Websites no longer show up properly using osx 10.6.8 ffox 36.0.1

    i am pretty sure it's the fact I am still using OSX 10.6.8 but some websites no longer show up properly the way they show up on OSX 10.10 even in safari websites no longer show up the way it does on the new OS. I have also downloaded the latest flash

  • LCD 20" Cinema Display Not Working on MBP

    Hi people! Somehow, the Apple Cinema Display (LCD) of 20" isn't working when I plug it to the MBP (late 2011). The monitor remains black after pluging it. Sometimes is detected by the MBP, and sometimes it isn't. Quite random thing. Same hapens when