Application of self-join interview question?

Hi guys!

I asked this question in an interview for the job as a developer of database.

I received a select based on symbol table and asked to drow the printout and then explain works step by step this statement.

Here are the instructions create & insert

/**********************************************/

create table tbl (number x, y varchar2 (50));

INSERT INTO tbl (x, y) VALUES ('A', 0);

INSERT INTO tbl (x, y) VALUES (1, 'B');

COMMIT;

/***********************************************/

Below the query (select statement)

SELECT tbl1.x

OF tbl tbl1 tbl2 tbl

WHERE tbl1.x = 0 OR tbl2.x = 1;

Please explain me the output and work step by step this statement...

Thank you...

Hello usman_noshahi,

If you omit the where the query clause will result as below

SELECT tbl1.x, tbl2.x

OF tbl tbl1 tbl2 tbl

/

X          X

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

0          0

0          1

1          0

1          1

Request granted will result as below based on where condition on each line on top 4 rows...  Or Condition will be returs real if one condition is met with the data set.

SQL > SELECT tbl1.x, tbl2.x

2 tbl tbl1 tbl2 tbl

3. WHERE tbl1.x = 0 tbl2.x = 1 GOLD

4.

X          X

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

0          0

0          1

1          1

SQL >

You can get the information in a different way as below...

SQL > explain plan set statement_id = "ORACLEFORUMS" for

2. SELECT tbl1.x

3 tbl tbl1 tbl2 tbl

4 WHERE tbl1.x = 0 OR tbl2.x = 1;

He explained.

SQL > select LPad (' ', 2 *(Level-1)). Level | '.' || NVL (position 0). ' ' ||

Operation 2. ' ' || Options of | ' ' || Object_name | ' ' || Object_type

3   || ' ' || Decode (id, 0, Statement_Id |) "Cost = ' | Position) | cost

4   || ' ' || Object_Node "Query Plan.

plan_table 5

6 start with id = 0 and statement_id = 'ORACLEFORUMS. '

7. connect by prior id = parent_id

8 and statement_id = 'ORAFAQ.

9   /

Query plan

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

1.7 STATEMENT SELECT ORACLEFORUMS cost = 77

2.1 NESTED LOOPS 7

3.1 ACCESS FULL TBL TABLE 3 TABLE

3.2 TABLE ACCESS FULL TBL TABLE 2

SQL > SELECT *.

TABLE 2 (DBMS_XPLAN. DISPLAY ('PLAN_TABLE', 'ORACLEFORUMS', 'BASIC'));

PLAN_TABLE_OUTPUT

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

Hash value of plan: 1718268327

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

| ID | Operation | Name |

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

|   0 | SELECT STATEMENT |      |

|   1.  NESTED LOOPS |      |

|   2.   TABLE ACCESS FULL | TBL |

|   5:   TABLE ACCESS FULL | TBL |

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

10 selected lines.

SQL >

SQL > select LPAD (' ', 2 *(LEVEL-1)). operation 'OPERATION', 'options ',.

2 DECODE (TO_CHAR (id), '0',' COST = ' |) NVL (to_char (position), n / 'a').

3 object_name) 'OBJECTNAME', id | » -'|| NVL (parent_id, 0) | » -'||

4 NVL (position 0), 'ORDER', SUBSTR (optimizer, 1, 6) 'OPT '.

plan_table 5

6. start with id = 0

7 and statement_id = 'ORACLEFORUMS. '

8 connect by prior id = parent_id

9 and statement_id = 'ORACLEFORUMS. '

10.

OPTIO OBJECTNAME OPT OPERATION ORDER

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

COST OF THE SELECT = 7 0-0-7 ALL_RO

NESTED LOOPS                                                                  1-0-1

TABLE ACCESS FULL TBL 2-1-1

TABLE 3-1-2 TBL FULL ACCESS

SQL >

ID ID-PARENT as follows...

00

10

21

31

Here level 1 has 2 childs (2,3)

Thus the sequential order of enforcement will be 2,3,1.

For more reference I recommend you read below, of course it's Oracle V8 but it gives more information.

Good reading!

Optimization of joins

Tags: Database

Similar Questions

  • Trying to wrap my brain around self-joins.

    Can't seem to understand the syntax or the logic underlying self-joins as seen in the code below:

    SELECT e1.last_name |' working for ' | E2.last_name 'employees and their Managers.

    E1, e2 employees employed

    WHERE e1.manager_id = e2.employee_id

    AND e1.last_name LIKE '% R '.

    ORDER BY e1.last_name;

    I understand all parts of this (I think) except this part: e1.manager_id = e2.employee_id

    I've been manually through the employees table, and there is no line where the manager_id = employe_id. But, however, the results are Oracle are as below:

    Employees and their managers

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

    RAJS works for Mourgos

    Raphaely working for the King

    Works of Rogers for Kaufling

    Russell works for the King

    What am I misunderstanding? Thank you!!

    talk2me wrote:

    So what you are saying is that:

    e1.employee_id = e2.manager_id that says:

    1st reference in the table employees (for example):

    employee_ID is 125 and has a manager whose manager_ID is 120

    ...

    ...

    All employees, whether they are responsible for or are not in the table 'employees '. Each person has a unique employe_id, whether or not he is Manager.

    In the recording with employee_id = 125, the manager_id is 120. And 120 exists as a number in the employees table.

    talk2me wrote:

    ...

    Because now we know the manager_ID as 120, we now go to the 2nd reference in the employees table and look 120 employee_ID and know who is this person. Then, this person is 125 Manager employee_ID.

    Is this correct thinking?

    Yes, that's correct.

    It would be clearer if you run queries individually while you run through the thought process that precedes.

    Given that we have two copies (e1 and e2) from the same table 'employees', take a look at the following:

    SQL>
    SQL> -- Row from first copy of employees (e1)
    SQL> select e1.employee_id, e1.manager_id, e1.last_name
      2    from hr.employees e1
      3   where e1.employee_id = 125;
    
    EMPLOYEE_ID MANAGER_ID LAST_NAME
    ----------- ---------- -------------------------
      125   120 Nayer
    
    1 row selected.
    
    SQL>
    SQL> -- Join condition is e1.manager_id = e2.employee_id
    SQL> -- But e1.manager_id = 120 from the query above. Substitute it in the join condition.
    SQL> -- So, now let's see what 120 = e2.employee_id returns.
    SQL> -- We check the second copy of employees (e2)
    SQL> select e2.employee_id, e2.manager_id, e2.last_name
      2    from hr.employees e2
      3   where e2.employee_id = 120;
    
    EMPLOYEE_ID MANAGER_ID LAST_NAME
    ----------- ---------- -------------------------
      120   100 Weiss
    
    1 row selected.
    
    SQL>
    SQL> --
    SQL> -- Both the results in one line
    SQL> --
    SQL> SELECT e1.employee_id as e1_employee_id,
      2      e1.manager_id as e1_manager_id,
      3      e1.last_name as e1_last_name,
      4      --
      5      e2.employee_id as e2_employee_id,
      6      e2.manager_id as e2_manager_id,
      7      e2.last_name as e2_last_name,
      8      --
      9      e1.last_name||' works for '||e2.last_name "Employees and Their Managers"
    10    FROM hr.employees e1, hr.employees e2
    11  WHERE e1.manager_id = e2.employee_id
    12    AND e1.employee_id = 125
    13  ORDER BY e1.last_name;
    
    E1_EMPLOYEE_ID E1_MANAGER_ID E1_LAST_NAME    E2_EMPLOYEE_ID E2_MANAGER_ID E2_LAST_NAME  Employees and Their Managers
    -------------- ------------- --------------- -------------- ------------- --------------- -------------------------------------------------------------
        125 120 Nayer 120      100 Weiss  Nayer works for Weiss
    
    1 row selected.
    
    SQL>
    SQL>
    

    employee_id 125 ("Nayer") has manager_id = 120.

    Return to the second copy of the employees and see who is 120.


    Don't forget, all manager_ids are present in the employee_ids table.

    Employee_id is unique.

    120 can only happen once in the column "employe_id." But it can be repeated in the column "manager_id".

    employee_id = 120 is "Weiss".

    So, "Nayer" works for "Weiss".

  • Typical interview question

    Hi all

    I have a typical interview question, I tried the solution, but did not find.

    1 Int that: scheduled backup RMAN is running normal and run DBA "shutdown" command for an interview without knowing about backup, will, RMAN work ends or gets killed?

    My answer: because it's a normal shutdown, it should wait until existing complete process and restrict new connections

    2 Int that: If there are two channels allocated for the backup of the db and a channel separate for archivelog, the rman job status is db backup is complete and has been asked to stop, he will start archivelog backup channel?

    Run {allocate channel d1 type disk;}

    allocate channel d2 type disk;

    backup database;

    output channel d1;

    output channel d2;

    allocate channel d3 type disk;

    ARCHIVELOG backup all;

    output channel d3;

    }

    I'm confused here, I tried to find the answer on the forum, as well as google, but did not find. Unfortunately I do not have a test machine to try this scenario myself. Therefore, ask your valuable contributions.

    Also let me know if my assumption is correct and to expect all connections stop normal and transactional (only users or RMAN, expdp, etc as well), I check this link, but it is not categorize connections http://docs.oracle.com/cd/E11882_01/server.112/e16604/ch_twelve042.htm

    Thank you very much in advance!

    AbbasDBA

    As the session already exists, rman allocates channels at the initial stage only, it reuses just channel placement phase by phase. So in this case it will not stop, it will continue with archives too

  • Need to reply and report interview question and Oracle Forms 10 G

    Hi gurus

    Soon, I expect my interview for Oracle Forms and Reports 10 G, I'd appreciate it if someone provides me with assistance to find the answers and the related question. Thank you

    Concerning

    Shu


    Hello

    Google is your friend

    http://www.coolinterview.com/type.asp?iType=64

    http://asset-9.soup.IO/asset/10511/3383_9441.PDF

    http://javarevisited.blogspot.com/2012/12/top-10-Oracle-interview-questions-and-answers-database-SQL.html

    Amatu Allah

  • Need answers to 2 interview questions

    Hi friends, need answers for interview questions 2

    1. the Virtual Machine is not manageable / connectable after successful vMotion. What is the reason?

    2. a company has 2 ESXi hosts, if one of the ESXi host fails, the virtual machines from the host failed ESXi does not move to the ESXi host direct. What could be the reasons.

    Kind regards

    Sirot Vijay

    Hello

    To confirm:

    (1) If you have a group of ports that exist on both hosts, but has been configured incorrectly on a specific host, which could cause the problem. That's the problem with the standard switches and port groups because they are configured individually for each host, which leaves room for human error. For example, you may have the incorrect VLAN ID assigned group of ports or switch on that is it might have an uplink that is different from the previous host. It is also possible that the port group is may not be configured on the host at all, it is possible to be overridden.

    (2) you can select the behavior of the virtual machine in the event of an appearance of HA. If you select the cluster and view the HA of vSphere features, you have "Options for the Virtual Machine.  Here it is possible to change the priority of restart of VM (it may be disabled) and also how the virtual machine behaves if the host is isolated from the network. These parameters could possibly prevent the virtual machine to restart during failover HA.

    I hope that makes sense!

    Kind regards

    Ryan

  • Need to interview for 2nd Interview Question round

    Hello

    Can someone throw me a last interview questions docs as I 2nd round of interview tomorrow for VMware admin.

    Your HELP will change my career personally and professionally I want to enter the field of virtualization.

    THANK YOU SO MUCH IN ADVANCE...

    I hope that it is late.

    What is the difference between LUN masking and zoning?

    How does the DVS?

    The difference between NFS vs FC vs SSD?

    Introduction to vSAN?

    vMotion vs SVMOtion vs XVMOtion?

    How to you understand distribution IOPS / s across virtual machines in a host?

    Etc...

    In this way, there may be several question on different areas (network, storage, calculation)

  • Last Interview Questions 2013

    Hi all

    Please give me VMware vSphere 5 latest interview questions and answers.

    Kind regards

    Kamlesh.

    According to me.

    When you talk about vSphere. It can have almost all areas: computing, network, storage, installation... etc... You need to through with the fundamentals of all of these areas.

    Just go through secure Channel 5 blueprint and prepare compared to the time you have. vSphere is large enough to learn over the years.

    Ref:http://mylearn.vmware.com/lcms/web/portals/certification/VCP_Blueprints/VCP5-DCV-VCP510-Exam-Blueprint-v3_1.pdf

    Select the themes that interest you by blue print top. Note: The Blue print is very detailed, so you must prioritize well and prepare.

    If you need an interview as an administrator, they can expect little more than a few basic principles. If its for Dev or QA, they can expect some basics from the point of view of vSphere.

    Apart from this, you must prepare your resume very well. 80% questions comes to your curriculum vitae as based on your CV, only you are pre-selected.

    Hope this will help prepare.

  • Interview questions ATG for 3 + experience

    Hello

    1. What are the important issues in the ATG for 3 + experience?

    2. What are the Questions they ask in the trade

    a. account management Module

    b. ShoppingCart Module

    Thank you

    Sudharsan.s

    Normally the Interview will begin with ATG Basics

    Formhandler, drop, Servlet, referential Pipeline, how to create the new repository, a relationship a-a, a - many, many. types of cache and cache modes.

    Then,

    If you have worked on the customization:

    Scenario, slot, targeting. Diff b/w and targetter scenario.

    If you have worked on trade:

    How to extend OOTB repositories, methods used on different pages: shopping cart page, the page of payment. IE, how to add article to the shopping cart, how to show the payment page, etc..

    How to create the trade pipeline string, link.

    How ATG pricing works.

    Read more:

    ATG Programming Guide (until the chapter of Servlet of Pipelines)

    Repository guide ATG (until the chapter of the Cache)

    ATG Commerce Programming Guide (till Pipeline Chains Chapter)

    There are a few messages on yahoo or in some blogs. Just ATG google interview questions.

    As experience grows, people will wait to know not only the names of methods, but how internally works ATG.

    Kind regards

    Nitin.

  • Technical interview question

    Hi all

    I need help. I have an interview in two days on the Pl/Sql developer, but I don't know about the technical question ask in an interview.

    If anyone has a technical interview question.

    Post your experienced question during an interview.

    Please answer.

    Thankx in advance.

    Post edited by: 66ae2845-affa-42cb-ba22-847accd179f1

    66ae2845-AFFA-42CB-BA22-847accd179f1 wrote:

    Hi I have knowledge but I don't know what kind of questions to ask in.

    This is the point of an interview, to test what knowledge you have, not what responses you tried to learn in advance.

    There is no interest to get you a job based on the responses, you learned that if you don't have the knowledge and the understanding that you will end up by given the work you do not know how.

    Go to the interview and answer all questions honestly you will be asked.

    It is better to say you don't know the answer, but demonstrate that you have an idea where you'd look to know, than to pretend, you know the answer when you have not, in which case you will be often caught in any case that the interviewer can dig to find out how well you understand the answer you gave (as an interviewer, it's what I would do).

  • VMware and answer interview questions

    VMware and answer interview questions

    I think that he referred interview VMware software-related issues, but he fails to mention the subjects he wants to have answers

  • G 10 Oracle interview questions

    Hello

    Please post the link for oracle 10g interview questions. IAM a developer (starter). Please help me.

    Thank you and best regards,
    Anill

    Published by: Anill February 10, 2012 23:46

    This should be useful.

    http://www.geekinterview.com/interview-questions/Oracle/PL-SQL

  • In weblogic server interview questions

    Hello

    Veuileez can you tell me everything time real maintenance issues to the server administration weblogic (8.1 or 9.2 and 10.3) or advice me how to details.


    Thanks in advance
    Bajaji kumar

    Hi Bajaji,

    Especially for the preparation of the interview... There is no such good site on WebLogic... but you can make reference to: http://crkthoughts.blogspot.com/2009/12/weblogic-faqs.html (RaviKiran) Blog to get an idea.

    E docs are always the best... to meet the... interview questions as well as for orders in real time...

    .
    .
    Thank you
    Jay SenSharma
    http://WebLogic-wonders.com/WebLogic (WebLogic wonders are here)

  • Required Portal WebLogic interview questions

    Hi all

    Required Portal WebLogic interview questions

    Thank you
    Surya

    Hi Surya,

    For the interview questions and answers please go through this blog http://venkataportal.blogspot.com/

    Thank you

    Published by: VenkataS on May 8, 2010 22:07

  • Self-joins in Discoverer?

    Hello

    I'm new to the discoverer. According to the "All discoverer" page, I use the following:
    OracleBI Discoverer 10g (9.0.4.00.00)
    Oracle Business Intelligence Discoverer Plus 10g (10.1.2.55.26)
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi

    I'm looking to create reports of discoverer of data requiring the self-joins, and I wonder if this is even possible.

    A simplified form of the query I use looks like the following:
    SELECT
            qll.operand
          , pa.list_header_id
          , pa.list_line_id
    
    FROM
            apps.qp_pricing_attributes        pa
          , apps.qp_pricing_attributes        pa1
          , apps.qp_pricing_attributes        pa2
          , apps.qp_list_lines                qll
    
    WHERE   qll.LIST_LINE_ID                  = pa.LIST_LINE_ID
    AND     pa.PRICING_ATTRIBUTE              = 'PRICING_ATTRIBUTE23'   -- ship dates
    
    AND     qll.list_line_id                  = pa1.list_line_id (+)
    AND     pa1.PRICING_ATTRIBUTE             = 'PRICING_ATTRIBUTE27'   -- origin
    
    AND     qll.list_line_id                  = pa2.list_line_id (+)
    AND     pa2.PRICING_ATTRIBUTE             = 'PRICING_ATTRIBUTE99'   -- item
    
    AND     pa.list_header_id                 =  12050      -- header id
    
    /******************************   TEST DATE   *********************************/
    AND     sysdate
                BETWEEN to_date(pa.PRICING_ATTR_VALUE_FROM,'YYYY/MM/DD HH24:MI:SS')
                AND     to_date(pa.PRICING_ATTR_VALUE_TO,  'YYYY/MM/DD HH24:MI:SS')
    Essentially, the above query returns price several attributes for a given rate and collapses them all to a single line of output.

    So are even possible in discoverer of self-joins? I note that in the documentation
    Oracle® Business Intelligence Discoverer Plus User Guide 10 g Release 2 (10.1.2.1) B13915-04
    the only reference to self-joins seems to be regarding the LAG function, although even that seems to offer very small overview of the use of this function.

    I guess I could ask a DBA to create a view and a report out of sight. But are there other options?

    THX.

    -Wayne

    In SQL * Plus, you can write the following SQL code
    Select a.empno, a.ename, b.empno, b.ename
    of the emp a, b of the emp
    where a.mgr = b.empno;

    In Discoverer, you cannot join EMP to itself.

    work around
    ========

    Import the EMP table in your sector of activity for
    a second time, giving you a table EMP1. Then, create a join between EMP and EMP1:

    EMP. MGR = EMP1. ENAME

  • Need help with a self-join query

    Hello
    I have A table with the following data

    OID parent_oid
    4 of 10
    4 2
    2 2
    12 6
    6 6

    parent_oid is the parent of the oid. I would like a query that displays the final parent of the oid. The result must indicate the following

    Final parent OID
    2 of 10
    4 2
    2 2
    12 6
    6 6

    I use Oracle 10 g. I am familiar with free joins, but that alone will not do the job. Thank you!

    Hello

    arizona9952 wrote:
    ... I am familiar with free joins, but that alone will not do the job.

    You are absolutely right!

    A self-join 2-way would work for lines have no parent, or lines which are directly related to their final ancestor (such as the oid = 4), but not for what anyone further.
    A 3-way self-join would work to a level more away from the last row, but no more. That would be enough with the small set of sample data that you posted, but it won't work if you have added a new rank parent_id = 10.
    An N - way self-join would work for up to N + 1 levels, but no more.

    You need something that can go to any number of levels, such as CONNECT BY:

    SELECT     CONNECT_BY_ROOT oid     AS oid
    ,     parent_oid          AS final_parent
    FROM     a
    WHERE     CONNECT_BY_ISLEAF     = 1
    CONNECT BY     oid     = PRIOR parent_oid
         AND     oid     != parent_oid
    ;
    

    Published by: Frank Kulash, February 22, 2010 19:09

    On sober reflection, I think that a request from top down, as one below, would be more effective than a motion up and down, like the one above:

    SELECT     oid
    ,     CONNECT_BY_ROOT     parent_oid     AS final_parent
    FROM     a
    START WITH     parent_oid     = oid
    CONNECT BY     parent_oid     = PRIOR oid
         AND     oid          != PRIOR oid
    ;
    

Maybe you are looking for

  • Sync works not for two days. Cleaning does not help.

    As a first step, it showed:"Sync met and the synchronization error: unknown error". Today it shows:«Sync encountered and error during synchronization: incorrectly configured server.» Even on all the computers I have synced. Tried to clean, by the way

  • HP 15ac122tu with Free back: cannot install drivers wifi and diusplay drivers for HP 15ac122tu

    I went through the various positions and solutions. I am still unable to install display drivers and the network drivers (wifi) for my HP 15ac122tu. Help, please. FCC ID: TX2-RTL8723BE Display drivers are not available, don't install that provided on

  • VISA makes about LV freeze

    Hello I use VISA read & write to interface a USB converter to FTDI FT232BL series. The FTDI driver created a virtual COM port. Everything worked fine with a few weeks with 8.51 LabVIEW 8.0 and 8.2. But all of a sudden my VI froze when I ran my stop c

  • HP 15: cannot make an image of the system

    I have a laptop HP 15. At 8.1 Windows installed 10 Windows, everything works fine until I try to create a system image. When I click to start it says create Windows 7 system image then fails to 97%. Two questions why Windows 7 and why failing. Thanks

  • Types of video files?

    When I tried to put a movie in format mp4 on my rocket, it said that the file type was not supported. I need to know what type of file, I should the converted to the range of the watch. Thanks in advance.