SELECT conditional from 2 tables

Hi all

What it the best way to apply this logic to SELECT when I'll select the folder with the unique ID of t_good REC but exist in other t_change with the same ID REC i ' l must be selected from there.
Something as IF it EXISTS, don't know how it works in Oracle. I see that I can REACH all records in table 2 and check them later, but might be much simpler?
If record with REC-ID exist in t_change 
   Select  * from t_change  
else
  Select * from t_ups_good  
TX
Trent

Since we do not know the data structure and you have no examples, we are a little limited to providing you with options. Because we are not sure how or where you do this, we are still limited to offering suggestions. That said, my first thought is to use a Union all.

Select * from t_change where recid = [recid]
Union All
Select  * from t_ups_good where (Select Count(1) From t_change where recid = [recid]) = 0

Tags: Database

Similar Questions

  • Select random from the tables

    Another problem of mine, I hope we can clear the air:
    I have 4-5 tables with different products, these products have a price. In another table, I have just a column with a value (my money). What I have to do, he chooses one product from each table and the sum of all should not be greater than my money? A randomization but how?
    If you need to learn more, say please and I'll post an example, I need help thanks

    Hello

    You can create the source of the page as a SQL something like element:

    WITH X AS (
    SELECT ROWNUM RR, DRINKS.NAME || ' ' || DRINKS.PRICE || ' ' || F1.PRODUCT || ' ' || F1.PRICE || ' ' || F2.PRODUCT || ' ' || F2.PRICE || ' ' || DESERT.PRODUCT || ' ' || DESERT.PRICE OUTPUT
    FROM MONEY M
    CROSS JOIN DRINKS
    CROSS JOIN F1
    CROSS JOIN F2
    CROSS JOIN DESERT
    WHERE DRINKS.PRICE + F1.PRICE + F2.PRICE + DESERT.PRICE <= M.MONEY)
    SELECT X.OUTPUT
    FROM X
    WHERE X.RR = TRUNC(DBMS_RANDOM.VALUE(1, (SELECT COUNT(*) FROM X)))
    

    Andy

  • read in select data from another table

    Hello world.

    IM Oracle11GR2 database.

    I m facing the following problem:

    I have 2 tables.

    In the first picture, I have a few articles and 3 of these items then come.

    (A) point Varchar2

    (B) Item Varchar2.

    (C) point digital and this point is the id of a record in the other table.

    If the digital point > 0 then points A and B must be read in the second table

    In the second table, I have 3 Articles.

    (A) the id of the record.

    B & C point are also point varchar2 and must be read in the first table, point C is > 0.

    I'm looking for the way that when I write a normal selection in the first picture he gives me the point B & C of the second table if C point in the first table is > 0.

    I thought to solve this problem with a trigger or something similar.

    Any idea is welcome.

    Regards to everyone.

    You don't need a trigger for this. A simple select statement should do. Something like that? I got your if condition perfectly.

    SELECT CASE WHEN (T1. C > 0) THEN (SELECT T2. B OF THE T2 WHERE T1. C = T2. (A) T1 OTHERWISE. END A,

    BOX WHEN (T1. C > 0) THEN (SELECT T2. C FROM T2 WHERE T1. C = T2. (A) T1 OTHERWISE. B END HAVE B,

    T1. C

    FROM T1;

    Look at the following example. Check if it fills your scenario.

    -BEGINNING OF THE SAMPLE DATA

    WITH T1 AS)

    SELECT 'A' A, 'B' B, 1 C OF DOUBLE UNION ALL

    SELECT 'C', ', 2 DOUBLE UNION ALL

    SELECT 'DF', 'G', THE DOUBLE 0),

    () AS T2

    SELECT 1, 'X' B 'Y' C DOUBLE UNION ALL

    SELECT 2, 'Z', 'BB' OF THE DOUBLE)

    -END OF THE SAMPLE DATA

    SELECT CASE WHEN (T1. C > 0) THEN (SELECT T2. B OF THE T2 WHERE T1. C = T2. (A) T1 OTHERWISE. END A,

    BOX WHEN (T1. C > 0) THEN (SELECT T2. C FROM T2 WHERE T1. C = T2. (A) T1 OTHERWISE. B END HAVE B,

    T1. C

    FROM T1;

    OUTPUT:

    A  B           C

    -- -- ----------

    X Y 1 - since c > 0 A and B values in table 2 are replaced

    Z BB 2 - since c > 0 A and B values in table 2 are replaced

    DF G 0 - since c = 0, there is even value in table 1

    Post edited by: Parth272025

  • How to insert point decimal all by selecting data from a table

    Hi all

    My select requirement says, if the value received with no decimal place then insert decimals before last 2 bytes. I need to recover the data with this condition.

    May help people how I can achieve this?

    Thanks in advance,
    Yvan

    997936 wrote:
    This will not work if the values are of 5 bytes.

    It should work for any number of digits...

    select 1234567/100 from dual;
    
    SELECT DECODE (INSTR (1234567, '.'), 0, 1234567 / 100, 1234567) FROM DUAL;
    

    Output:

    12345,67

    See you soon,.
    Manik.

    Published by: Marty on April 4, 2013 08:53

  • Form check synchronize on Popup to the selected record from the table

    I'm trying to recreate what I did on the portals of the OAS in Weblogic/ADF. I have JDeveloper 11.1.1.2.0. What I do seems to be a little different than the tutorials: I need something like the tutorial master-detail, but instead the details appearing on the same page, it should appear in a popup. I managed to build the part table/popup. But when the popup appears, it displays the wrong record. Here are the steps I used to create this page:

    After you create the ADF Fusion Middleware project:

    1 create templates for the tables I need.
    2. create the JSF Page.
    3 drop panelCollection on the page.
    4. remove my data to see in panelCollection control and choose the Table read-only ADF. Select the sorting and selection options.
    5 change table properties: selected = DisplayRow, EditingMode = clickToEdit
    6 drag the Popup on the page.
    7. remove my data from view in popup control and choose the form of the ADF. Select the send option.
    8 drop showPopupBehavior on the page. Name of the popup. The value triggerType to the 'selection '. (triggerType "click" works, too)
    9 deploy.

    The table is displayed. I click on a line. The pop-up window appears. The form of popup displays the first record in the table. I click on any line.

    I just bought the merger Oracle 11g Developer Guide, but were not able to answer this question yet.

    Any ideas?

    Thank you.

    See this video for how it works for me:
    http://www.ScreenToaster.com/watch/stWUtcRkVLQ1BcSV1aX15Q

  • Create the form for selecting data in multiple tables

    Hello

    I'm getting APEX for the first time and I just read 2 days dev Application Express guide

    I tried to play and I can't create a report with the form that select data from several tables

    What I want to achieve is a report we'll say 'USERS' makes MANAGER_ID ID, NAME, with a form that allows me to create, delete, change users

    The problem is that, once the report with the form created, if I click on create (to create a user) it will ask me for id, name, and manager_id

    I need a water drop down which allows me to select managers in the table manager instead of manually insert Director id

    How do I do that?

    Thank you!

    HI Chris,

    LOV will use this magic.

    Search:

    Kind regards

    BEnjamin

  • expdp + query option to export from several tables with the same condition

    Hello

    We want to export a subset of data only from databases to another. Both on AIX.

    Source/testdatabase 11.2.0.3 (non partitioned tables)
    Target productiion 11.2.0.3 database (separate tables)

    Tables of same names of columns but diffrenet structures a partitioning index and traget so only want to import content

    Each source datbaase hascolumn seq number table and want only to extract the last months of data.


    TABLES:table1,table2...
    DUMPFILE=dump_dir
    CONTENT=data_only
    QUERY= table1:"WHERE seq_num >100 "
    want to use expdp but not sure how to make sure that all tables have the seq_num WHERE > 100 condition, if let table1: go out and have just
    QUERY = "WHERE seq_num > 100"this condition would apply to all tables that we want."


    I'm assuming that can also use impdp CONTENT = data_only?

    Any ideas/thoughts?

    Thank you

    QUERY = "WHERE seq_num > 100"this condition would apply to all tables that we want."

    Yes, it will work for all tables, but ensure that all exported table must include this column.

    QUERY
    Default: no
    Goal
    Allows you to filter the data that is exported by specifying a clause of a SQL SELECT statement, which is applied to all tables in the work of export or a specific table.

    The query_clause is usually a WHERE clause for the selection of refined lines, but could be any SQL clause. For example, an ORDER BY clause can be used to accelerate a migration from a table in a heap in a table held in index. * If a [schema]. table_name is not provided, the query is applied to (and must be valid for) all tables in the export job.*

    http://docs.Oracle.com/CD/B19306_01/server.102/b14215/dp_export.htm

  • DB connectivity Kit: syntax error in a SELECTION of data from joined tables

    Hello everyone

    I'm putting in labview a SQL query on joined tables.

    As an example I take a database to store the data of basketball 2on2 matches, which tables are

    corresponds to (matchId, Thomas, teamB)

    teams (teamId,PlayerAname, PlayerBname, nationality)

    nationalities (NatId, natName)

    To get an array of result with the game as well as the names of player as well as their nationality, I use this query on MySQL (which works on command line interface)

    SELECT MatchID,
    T1. PlayerAName, t1. PlayerBName, n1.natName,
    T2. PlayerAName, t2. PlayerBName, n2.natName
    MATCHES m
    INNER JOIN teams t1 ON t1.teamID = m.teamA
    INNER JOIN teams t2 ON t2.teamID = m.teamB
    INNER JOIN nationalities L1 ON n1.natID = t1.nationality
    INNER JOIN nationalities n2 ON n2.natID = t2.nationality

    When I put it in labview, using the block 'select data', I get a syntax error as shown in the attached screenshot.

    Am I something mistanking using the JOIN examples statements or aliases?

    Thanks in advance!

    The select VI is designed to be a simple way to select from a table. I doubt that he can do joins (and would not certainly need the 'FROM', even if it can). What you can do instead calls the query execute VI and give him the complete SQL query. I don't remember if it returns the data in the recordset object, so you must do so separately.

  • To create an interactive report in the apex by selecting from multiple tables

    Hi, I am creating an interactive report by selecting from multiple tables.

    SELECT w.FIRST_NAME as name, w.SURNAME as name, i.ROAD Road, i.DATE_OF_INC as DATE_OF_INC, S.STATEMENT as a STATEMENT OF Declaration

    JOIN THE

    WITNESS w

    ON w.witness_id = s.FK1_WITNESS_ID

    JOIN THE

    Incident I have

    WE

    i.incident_no = w.FK1_INCIDENT_NO

    JOIN THE

    user_station ps

    ON ps.station_id = i.nearest_station_id

    JOIN THE

    the user in.

    WE

    in. STATION_ID = ps.station_id

    WHERE po.officer_id = 1

    by I continue to encounter this error "the report query requires a unique key to identify each row. The supplied key cannot be used for this query. Please change the report attributes to define a unique key column. "ORA-01445: cannot select ROWID from where sample, a join without key preserved table view '

    So I googled around and found that in the attibutres tables report, I need to change the "LINK" COLUMN so first, I changed "Link to custom target", but the report is so I changed it to "Exclude link Clolumn" again, the report didn't report and I STILL got a blank page with only the tabs.

    I wonder you can not create a report by selecting from multiple tables?

    If you can please I need your help.

    Thank you

    You can, but in this case, it might be easier to build your report tables that are joined Oracle views and then build your report out of the newly built sight...

    Or wrap a selection around your selection with joins, and then make the where clause on the external selection...

    Thank you

    Tony Miller
    Software LuvMuffin
    Ruckersville, WILL

  • Select from different tables based on results

    How to do this in a select

    4 paintings

    T3 and t4 are identical in structure, but different data

    Select the id of the t1

    If exist in select t2 id

    Then select the data on t3

    on the other

    Select the data on t4

    create table t1 (ID);

    create table t2 (ID);

    create table t3 (varchar2 (10) col1, col2 varchar2 (10));

    create table t4 (varchar2 (10) col1, col2 varchar2 (10));

    Insert into t1 values (1);

    Insert into t1 values (2);

    Insert into t2 values (1);

    Insert into t3 values('DATA1','DATA2');

    Insert into t4 values('DATA3','DATA4');

    commit;

    Ive had the values 1 and 2 in t1. ID = 1 exist in t2, for this record, I want I want the values of t3 but where id = 2, the t4 values.

    Possible in a select?   Ive been playing with case statement but not anywhere near him

    Try this

    Select *.

    T3

    where exists (select 1 from T1 t where t.id in (select t2.id T2))

    ----

    Union of all the

    ----

    Select *.

    T4

    where does not exist (select 1 from T1 t where t.id in (select t2.id T2))

    -----

    Ramin Hashimzade

  • You will need to select the rows that have been deleted from the table.

    Please help me with this query

    I'm trying to find the records has been deleted from a table.

    I know recovery flash but I want to check with the request.

    Please help me with this...

    You can see the folders by using the flashback feature, if it is available in the undo data

    SQL> delete from tbl_x;
    
    3 rows deleted.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> select * from tbl_x;
    
    no rows selected
    
    SQL> select * from tbl_x as of timestamp to_timestamp(sysdate-5/24/60);
    
            ID TOTAL_DAYS   NO_DAYS1   NO_DAYS2   NO_DAYS3 START_PER END_PERIO
    ---------- ---------- ---------- ---------- ---------- --------- ---------
             1         20         10          5          5 01-JAN-01 01-JAN-02
             1         10          5          5          0 11-MAY-01 11-MAY-03
             2          4          4          0          0 15-FEB-02 15-FEB-03
    
  • How to select data from a remote database table?

    Hi friends,

    I think I've seen before a sqlplus program that can select data from a remote database table?

    Witnessed: IP, SID, PORT

    The following is correct?

    (I am connected to a local database)
    SELECT COUNT (*) IN THE EMP@IP:SID/PORT;


    Thank you very much


    Ms. K

    Salvation;

    I think, that you can create dblink wihtout any problem yet, it's a PROD. After your selection, you can drop dblink

    Respect of
    HELIOS

  • Update with select table from another table

    Hallo,

    I'd like to update table b with a mapping a table codes.

    one has:

    town_id, town_code, town_name

    b town_code, town_id, town_population, town_zip_code...

    Table a has all the details - town_id, town_code and town_name and acts as the mapping between town_id and town_code

    In table b, town_code is null. I want to update the column b.town_code with town_code table where a.town_id = b.town_id.

    How the update query will look like?

    I tried
    UPDATE B SET town_code = (SELECT A.town_code FROM A, B WHERE A.town_id = B.town_id)

    and I get the error "einreihig subquery returns several lines.

    You will appreciate your assistance

    OK, now I see where you went wrong.

    It's your query:

    UPDATE TOWN_INFO
    SET TOWN_CODE=(SELECT B.TOWN_CODE FROM TOWN_MAPP B, TOWN_INFO C
    WHERE B.TOWN_ID=B.TOWN_ID)
    /
    

    You have added an additional TOWN_INFO table reference in your subquery. You really wanted to refer to the TOWN_INFO in your UPDATE statement for that to be a CORRELATED subquery. Delete this reference as I did below.

    Here's the correct query:

    UPDATE  TOWN_INFO TI
    SET     TOWN_CODE = (
                            SELECT  TOWN_CODE
                            FROM    TOWN_MAPP TM
                            WHERE   TI.TOWN_ID = TM.TOWN_ID
                    )
    ;
    
  • How to read/select only the records from a table with non-English characters

    Hello
    I need to find all records in a table with non-English (mainly Chinese) characters in at least one of the varchar2 columns. Let me kow if someone knows a way by which it can be done using SQL/PLSQL.

    Best regards
    Imran
    select * from your table
    where your_column != convert(your_column, 'UTF8', 'US7ASCII)
    

    Replace UTF8 with your database character set

    Published by: thtsang on October 15, 2009 03:53 - unequal sign change of! =

  • Select from another table, when the query returns no result

    Hello

    I have a question where I'm supposed to retrieve the address of an account id-based billing. However, the table of billing may not have an address. There is a table of addresses that always has an address for an account. If the billing address exists, it should be used, so I can't use the address table. Is it possible in a select statement to query to the billing address and if it does not exist, use the address table.

    SELECT * FROM accounts a, b billings WHERE a.accountid = b.accountid

    Any help will be greatly appreciated.

    Thank you.

    user10407139 wrote:
    Hello

    I have a question where I'm supposed to retrieve the address of an account id-based billing. However, the table of billing may not have an address. There is a table of addresses that always has an address for an account. If the billing address exists, it should be used, so I can't use the address table. Is it possible in a select statement to query to the billing address and if it does not exist, use the address table.

    SELECT * FROM accounts a, b billings WHERE a.accountid = b.accountid

    Any help will be greatly appreciated.

    I think you need to explain more clearly if

    -you only have a couple of "billing" columns which is empty and in this case, you want to use the columns from the table 'accounts '.

    - or you have a join with another table that doesn't return data, for example a foreign key "address_id" "billing" is zero and therefore the join to other tables 'address' will return all the data

    In the first case, you have already been provided with some examples here, how to use NVL or similar functions to achieve, even if the first post first evaluates the information of 'accounts' and if it is white using information from "billing". According to your description you need the other way around. The second post a subquery recursive useless in my opinion.

    In the latter case, you should probably use an "outer" join so that the data in your table "bills" are returned, even if the join to another table is not at all the lines.

    SELECT
    NVL(AD1.ADDRESS_ATTR1, AD2.ADDRESS_ATTR1) as ADDRESS_ATTR1,
    NVL(AD1.ADDRESS_ATTR2, AD2.ADDRESS_ATTR2) as ADDRESS_ATTR2,
    NVL(AD1.ADDRESS_STREET, AD2.ADDRESS_STREET) as ADDRESS_STREET,
    ...
    FROM accounts a
    INNER JOIN billings b
    ON a.accountid = b.accountid
    LEFT OUTER JOIN address ad1
    ON b.address_id = ad1.address_id
    INNER JOIN address ad2
    ON a.address_id = ad2.address_id;
    

    In this way you pick up the address stored in the "invoices" table, if it existed, otherwise you pick up the address assigned to the "accounts" table I used an inner for the second address join join because you said that the account always has an assigned address.

    Kind regards
    Randolf

    Oracle related blog stuff:
    http://Oracle-Randolf.blogspot.com/

    SQLTools ++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676 /.
    http://sourceforge.NET/projects/SQLT-pp/

Maybe you are looking for