EMP table query

Hi friends,

Please help me get the following output from the EMP table:
DEPTNO     EMPNO     ENAME     SAL      HIREDATE
------------------------------------------------------------------------------------
10             7521        Arun         1000    01-Jan-2005
                7522       Bala           2000    01-Feb-2005 
                7523        Chitra         3000    01-Mar-2005
20             7524        Divya         4000    01-Apr-2005
                7525        Elango        5000    01-May-2005 
30             7526        Fathima      6000    01-Jun-2005
                7527        Gopal         7000     01-Jul-2005
                7528        Hari            8000    01-Aug-2005
Published by: BluShadow on February 15, 2012 08:29
addition of {noformat}
{noformat} tags for improved (not perfect, due to OP's source) readability.  Please read {message:id=9360002} and learn to do this yourself.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

According to my understanding, you could require something like this:

     DEPTNO      EMPNO ENAME             SAL HIREDATE
---------- ---------- ---------- ---------- ---------
        10       7934 MILLER           1300 23-JAN-82
                 7839 KING             5000 17-NOV-81
                 7782 CLARK            2450 09-JUN-81
        20       7876 ADAMS            6200 12-JAN-83
                 7369 SMITH             800 17-DEC-80
                 7788 SCOTT            3000 09-DEC-82
                 7566 JONES            2975 02-APR-81
                 7902 FORD             3000 03-DEC-81
        30       7844 TURNER           1500 08-SEP-81
                 7698 BLAKE            2850 01-MAY-81
                 7521 WARD             1250 22-FEB-81
                 7499 ALLEN            1600 20-FEB-81
                 7521 WARD             6500 22-FEB-81
        40       7900 JAMES            5900 03-DEC-81
                 7654 MARTIN           6500 28-SEP-81

Then, the query you could use is:

SELECT (CASE WHEN rn = 1 THEN deptno ELSE NULL END) Deptno, empno, ename, sal, hiredate
FROM (
SELECT deptno, ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY empno) rn ,empno, ename, sal, hiredate
FROM emp); 

Published by: claire on February 14, 2012 23:17

Tags: Database

Similar Questions

  • SELECT on the emp table query

    Hello


    How to find the display the o/p as a manager name under employees dependent child parent like relation ship on the noraml emp table:

    sample o/p:

    use of name
    Nativity scene XX
    sales of yy
    YY1 sales
    Manager of the AA
    marketing of RR
    RR1 marketing


    Thank you

    921306 wrote:

    So I need, like that, child-parent relationship between the Manager under employees...

    Then join the parent with the child entity entity to create the parent-child relationship.

    The two entities are in the same table, it means to join the table to itself. For example

    SQL> select
      2          child.ename                     as CHILD,
      3          child.job                       as CHILD_JOB,
      4          nvl(parent.ename,'')      as PARENT,
      5          parent.job                      as PARENT_JOB
      6  from emp parent,
      7       emp child
      8  where child.mgr = parent.empno (+)
      9  /
    
    CHILD      CHILD_JOB PARENT     PARENT_JO
    ---------- --------- ---------- ---------
    FORD       ANALYST   JONES      MANAGER
    SCOTT      ANALYST   JONES      MANAGER
    JAMES      CLERK     BLAKE      MANAGER
    TURNER     SALESMAN  BLAKE      MANAGER
    MARTIN     SALESMAN  BLAKE      MANAGER
    WARD       SALESMAN  BLAKE      MANAGER
    ALLEN      SALESMAN  BLAKE      MANAGER
    MILLER     CLERK     CLARK      MANAGER
    ADAMS      CLERK     SCOTT      ANALYST
    CLARK      MANAGER   KING       PRESIDENT
    BLAKE      MANAGER   KING       PRESIDENT
    JONES      MANAGER   KING       PRESIDENT
    SMITH      CLERK     FORD       ANALYST
    KING       PRESIDENT 
    
    14 rows selected.
    
    SQL> 
    

    The basic concept is easy - set the parent entity, set the child entity, join the parent to the child.

    If some entities will not have parents (root entities), then an outer join is required of the child entity to the parent entity.

    Everything simply because the two entities are in the same table, does not change the logic or the approach. It's perfectly valid for a join table.

  • selecting max 5 salaries in the emp table

    Hi I tried the following query to obtain the emp table max 5 salaries...
    SQL> select sal
      2  from (select sal,empno from emp order by sal desc
      3  where rownum<6;
    
           SAL
    ----------
          5000
          3000
          3000
          2975
          2850
    But here in the output of the duplicate rows are there... I need to remove this and number total should be equal to only 5...
    If I put the distinct clause, then I'll take 4 rows only... but I need the salaries of the top 5...

    Thank you
    select *
      from (
    select distinct sal
      from emp
     order by sal desc
     ) where rownum <= 5
    ;
    
  • Elapsed time for the materialized view vs Master table query

    Hello all;

    Small confusion about time up for the vs Master materialized view table query

    SQL > select count (*), sum (quan_sold), sum (amt_sold) of the sale;
    COUNT (*) SUM (QUAN_SOLD) SUM (AMT_SOLD)
    6000000 12000000 720480000
    Elapsed time: 00:00:30.54
    SQL > create materialized view mv1
    2 activate the rewrite of the query as
    3. select count (*), sum (quan_sold), sum (amt_sold) of the sale;
    Materialized view created.
    Elapsed time: 00:00:01.45
    SQL > select count (*), sum (quan_sold), sum (amt_sold) of the sale;
    COUNT (*) SUM (QUAN_SOLD) SUM (AMT_SOLD)
    6000000 12000000 720480000
    Elapsed time: 00:00:00.01

    Please see the three cases "Elapsed Time"...

    When comparing other cases.
    1. my query takes long time (30.54), extraction of data from the sale
    2. create a materialized view takes less time (01:45) why?

    Source: http://uhesse.com/2009/07/08/brief-introduction-into-materialized-views/

    >
    Small confusion about elapsed time for the materialized view vs Master table query

    SQL > select count (*), sum (quan_sold), sum (amt_sold) from the sale.

    COUNT (*) SUM (QUAN_SOLD) SUM (AMT_SOLD)
    6000000 12000000 720480000
    Elapsed time: 00:00:30.54

    SQL > create materialized view mv1
    2 activate the rewrite of the query as
    3. select count (*), sum (quan_sold), sum (amt_sold) of the sale;
    Materialized view created.
    Elapsed time: 00:00:01.45

    SQL > select count (*), sum (quan_sold), sum (amt_sold) from the sale.

    COUNT (*) SUM (QUAN_SOLD) SUM (AMT_SOLD)
    6000000 12000000 720480000
    Elapsed time: 00:00:00.01

    Please see the three cases "Elapsed Time"...

    When comparing other cases.
    1. my query takes long time (30.54), extraction of data from the sale
    2. create a materialized view takes less time (01:45) why?
    >
    Many queries take less time the second time you run them. After the first performance, there may be many, if not all, lines in the buffer cache. Then the second round will not make any or all e/s physical but will obtain data from the buffer cache.

    Also, you haven't checked that the MV was even used for the second run.

    Drop the MV and make the query several times and means of the time. Then create the MV and do the same thing.

  • cloumn on the emp table online

    Hello world

    I want to do EMP table in columns by departments
    under the name of employees of each Department

    for example,.

    10. 20
    CLARK | SMITH
    KING | FORD
    MILLER | ADAMS

    Thank you

    You mean like this?

    SQL> select * from emp;
    
         EMPNO ENAME      JOB              MGR HIREDATE                    SAL       COMM     DEPTNO
    ---------- ---------- --------- ---------- -------------------- ---------- ---------- ----------
          7369 SMITH      CLERK           7902 17-DEC-1980 00:00:00        800                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-1981 00:00:00       1600        300         30
          7521 WARD       SALESMAN        7698 22-FEB-1981 00:00:00       1250        500         30
          7566 JONES      MANAGER         7839 02-APR-1981 00:00:00       2975                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-1981 00:00:00       1250       1400         30
          7698 BLAKE      MANAGER         7839 01-MAY-1981 00:00:00       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-1981 00:00:00       2450                    10
          7788 SCOTT      ANALYST         7566 19-APR-1987 00:00:00       3000                    20
          7839 KING       PRESIDENT            17-NOV-1981 00:00:00       5000                    10
          7844 TURNER     SALESMAN        7698 08-SEP-1981 00:00:00       1500          0         30
          7876 ADAMS      CLERK           7788 23-MAY-1987 00:00:00       1100                    20
          7900 JAMES      CLERK           7698 03-DEC-1981 00:00:00        950                    30
          7902 FORD       ANALYST         7566 03-DEC-1981 00:00:00       3000                    20
          7934 MILLER     CLERK           7782 23-JAN-1982 00:00:00       1300                    10
    
    14 rows selected.
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  with d1 as (select ename, row_number() over (order by empno) as rn from emp where deptno = 10)
      2      ,d2 as (select ename, row_number() over (order by empno) as rn from emp where deptno = 20)
      3      ,d3 as (select ename, row_number() over (order by empno) as rn from emp where deptno = 30)
      4  --
      5  select d1.ename as dept10, d2.ename as dept20, d3.ename as dept30
      6  from   d1 full outer join d2 on (d2.rn = d1.rn)
      7*           full outer join d3 on (d3.rn = nvl(d2.rn,d1.rn))
    SQL> /
    
    DEPT10     DEPT20     DEPT30
    ---------- ---------- ----------
    CLARK      SMITH      ALLEN
    KING       JONES      WARD
    MILLER     SCOTT      MARTIN
               ADAMS      BLAKE
               FORD       TURNER
                          JAMES
    
    6 rows selected.
    

    As already mentioned, in a reporting tool is much better.

  • Unique problem with selction on the table (Query Page)

    Unique problem with selction on the table (Query Page)

    I have a VO data Bulletin Board, with a transitional attribute for selction unique column.
    My requirement is that I need to identify the line that was selected in the table.

    I associated with fireAction singleSelection column, such that whenever the user selects the line
    I'm looking for that VO using some rowIterator.
    But when running the loop of the transient VO that is mapped to the singleSelection variable is the show as "n" / NUll
    for all the lines...

    So how do you identify the selected line in singleSelection to a table.

    -Sasi

    In the property inspector of the element for which you've put firePartialAction, you can find a property named "parameters". That mention primary key as your setting.

    You can get the arameter using pageContext.getparameter ();

    -Anand

  • How to insert 10,000 records test data into the emp table

    Hi I am new to oracle can someone please help me write a program so that I can insert the test data into the emp table
    SELECT       LEVEL empno,
                 DBMS_RANDOM.string ('U', 20) emp_name,
                 TRUNC (DBMS_RANDOM.VALUE (10000, 100000), 2) sal,
                 DBMS_RANDOM.string ('U', 10) job,
                 TO_DATE ('1990-01-01', 'yyyy-mm-dd')
                 + TRUNC (DBMS_RANDOM.VALUE (1, 6000), 0)
                   hiredate,
                 CASE
                   WHEN LEVEL > 10 THEN TRUNC (DBMS_RANDOM.VALUE (1, 11), 0)
                   ELSE NULL
                 END
                   mgr,
                 TRUNC (DBMS_RANDOM.VALUE (1, 5), 0) deptno
    FROM         DUAL
    CONNECT BY   LEVEL <= 10000
    
  • get the cumulative sum of the salaries of the employees of emp table

    Hi gurus,

    Can any body tell me how to get the cumulative sum of the salaries of the employees in the emp table using analytical functions.

    Thanks in advance...

    Please read the document

    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/functions163.htm#sthref2186

    Look for example at the bottom of the document.

  • How can I get the second and third highest salary from the emp table

    How can I get the second and third highest salary from the emp table in the ecah Department
    SQL> ed
    Wrote file afiedt.buf
    
      1  select empno, ename, sal, deptno
      2  from (
      3    select empno, ename, sal, deptno, dense_rank() over (partition by deptno order by sal desc) as rn
      4    from emp
      5    )
      6* where rn in (2,3)
    SQL> /
    
         EMPNO ENAME             SAL     DEPTNO
    ---------- ---------- ---------- ----------
          7782 CLARK            2450         10
          7934 MILLER           1300         10
          7566 JONES            2975         20
          7876 ADAMS            1100         20
          7499 ALLEN            1600         30
          7844 TURNER           1500         30
    
    6 rows selected.
    
    SQL>
    
  • foreign key ALTER TABLE QUERY PROBLEM

    HAI ALL,

    ANY SUGGESTION PLEASE?

    UNDER: foreign key ALTER TABLE QUERY PROBLEM

    I want TO CREATE AND ALTER TABLE foreign key:

    1.TABLE:HAEMATOLOGY1
    COLUMN: HMTLY_PATIENT_NUM
    WITH
    TABLE: PATIENTS_MASTER1
    COLUMN: PATIENT_NUM (THIS IS THE KEY PRIMARY AND UNIQUE)

    1.TABLE:HAEMATOLOGY1
    COLUMN: HMTLY_TEST_NAME
    WITH
    TABLE: TESTS_MASTER1
    COLUMN: TEST_NAME ((C'EST LA CLÉ UNIQUE))
    ---------------


    SQL + QUERY DATA:
    -----------
    ALTER TABLE HAEMATOLOGY1
    Key constraint SYS_C002742_1 foreign (HMTLY_PATIENT_NUM)
    references PATIENTS_MASTER1 (PATIENT_NUM);

    ERROR on line 2:
    ORA-01735: invalid option of ALTER TABLE

    NOTE: THE NAME OF THE CONSTRAINTS: SYS_C002742_1 TAKEN FROM ORACLE ENTP TABLE DETAILS. MGR.
    ---------
    ALTER TABLE HAEMATOLOGY1
    Key constraint SYS_C002735_1 foreign (HMTLY_TEST_NAME)
    references TESTS_MASTER1 (TEST_NAME);

    ERROR on line 2:
    ORA-01735: invalid option of ALTER TABLE

    NOTE: THE NAME OF THE CONSTRAINTS: SYS_C002735_1 TAKEN FROM ORACLE ENTP TABLE DETAILS. MGR.

    ==============

    4 TABLES OF LABORATORY CLINIC FOR DATA ENTRY AND GET REPORT ONLY FOR THE TESTS CARRIED OUT FOR PARTICULAR

    PATIENT.

    TABLE1:PATIENTS_MASTER1
    COLUMNS: PATIENT_NUM, PATIENT_NAME,

    VALUES:
    PATIENT_NUM
    1
    2
    3
    4
    PATIENT_NAME
    BENAMER
    GIROT
    KKKK
    PPPP
    ---------------
    TABLE2:TESTS_MASTER1
    COLUMNS: TEST_NUM, TEST_NAME

    VALUES:
    TEST_NUM
    1
    2
    TEST_NAME
    HEMATOLOGY
    DIFFERENTIAL LEUKOCYTE COUNT
    -------------

    TABLE3:HAEMATOLOGY1
    COLUMNS:
    HMTLY_NUM, HMTLY_PATIENT_NUM, HMTLY_TEST_NAME, HMTLY_RBC_VALUE, HMTLY_RBC_NORMAL_VALUE

    VALUES:
    HMTLY_NUM
    1
    2
    HMTLY_PATIENT_NUM
    1
    3
    MTLY_TEST_NAME
    HEMATOLOGY
    HEMATOLOGY
    HMTLY_RBC_VALUE
    5
    4
    HMTLY_RBC_NORMAL_VALUE
    4.6 - 6.0
    4.6 - 6.0
    ------------

    TABLE4:DIFFERENTIAL_LEUCOCYTE_COUNT1
    COLUMNS: DLC_NUM, DLC_PATIENT_NUM, DLC_TEST_NAME, DLC_POLYMORPHS_VALUE, DLC_POLYMORPHS_

    NORMAL_VALUE,

    VALUES:
    DLC_NUM
    1
    2
    DLC_PATIENT_NUM
    2
    3
    DLC_TEST_NAME
    DIFFERENTIAL LEUKOCYTE COUNT
    DIFFERENTIAL LEUKOCYTE COUNT
    DLC_POLYMORPHS_VALUE
    42
    60
    DLC_POLYMORPHS_NORMAL_VALUE
    40-65
    40-65
    -----------------


    Thank you
    RCS
    E-mail:[email protected]
    --------

    ALTER TABLE HAEMATOLOGY1
    ADD Key constraint SYS_C002742_1 foreign (HMTLY_PATIENT_NUM)
    references PATIENTS_MASTER1 (PATIENT_NUM);

  • How to display data from the emp table?

    Hi everyone, this is my first post in this portal. I want to display the details of the table emp... for this I use this SQL statement.

    Select * from emp where mgr = nvl(:mgr,mgr);

    When I give the entry as 7698 it shows the matching records... and also when I don't give any input then it shows all the records except the Archbishop with null values.

    (1) I want to display all the records when I do not give any input, including null values
    (2) I want to display all the records that a Bishop is null

    Is it possible to integrate in order to include all these in a single query.

    Hello

    937440 wrote:
    Hi everyone, this is my first post in this portal.

    Welcome to the forum!
    Don't forget to read the forum FAQ {message identifier: = 9360002}

    I want to display the details of the table emp... for this I use this SQL statement.

    Select * from emp where mgr = nvl(:mgr,mgr);

    When I give the entry as 7698 it shows the matching records... and also when I don't give any input then it shows all the records except the Archbishop with null values.

    (1) I want to display all the records when I do not give any input, including null values
    (2) I want to display all the records that a Bishop is null

    Is it possible to integrate in order to include all these in a single query.

    It's a little unsure what you're asking.
    The following query always includes the lines where mgr is NULL and when the binding variable: mgr is NULL, it displays all the lines:

    SELECT  *
    FROM     emp
    WHERE     LNNVL (mgr != :mgr)
    ;
    

    In other words, when: 7698 = mgr, it displays 6 rows and when: mgr is NULL, it displays 14 rows (assuming you are using the table provided by Oracle scott.emp).

    The following query includes lines where Bishop is ZERO only when the binding variable: mgr is NULL, in which case it shows all lines:

    SELECT     *
    FROM     emp
    WHERE     :mgr     = mgr
    OR       :mgr       IS NULL
    ;
    

    When: mgr = 7698, this will display 5 rows and when: mgr is NULL, it displays 14 rows.

    The following query includes lines where Bishop is ZERO only when the link variab; e: mgr is NULL, in which case it shows only those rows where mgr is NULL. In other words, it treats NULL as a value:

    SELECT     *
    FROM     emp
    WHERE     DECODE ( mgr
                , :mgr, 'OK'
                )     = 'OK'
    ;
    

    When: mgr = 7698, this will display 5 rows and when: mgr is NULL, it displays 1 row.

  • minimum hiredate from the emp table

    Hello

    There is a table EMP, hiredate column (date). I want to get the record with minimum hiredate and using this query.
    SQL> select * from v$version;
    
    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE    10.2.0.4.0      Production
    TNS for Solaris: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    
    SQL> with t as
      2  (select 'A' ename, 1 enum, '1-Oct-2008' hiredate from dual union all
      3  select 'B', 2, '1-Jan-2002' from dual union all
      4  select 'C', 3, '1-Mar-2008' from dual)
      5  select * from t
      6  where hiredate = (select min(hiredate) from t);
    
    E       ENUM HIREDATE
    - ---------- ----------
    B          2 1-Jan-2002
    
    SQL> 
    Is there another way to do it, without using subquery?

    Kind regards
    Ritesh

    Another option:

    SELECT  MIN(ENUM)       KEEP (DENSE_RANK FIRST ORDER BY HIREDATE)       AS ENUM
    ,       MIN(HIREDATE)   KEEP (DENSE_RANK FIRST ORDER BY HIREDATE)       AS HIREDATE
    FROM    t
    

    EDIT: See the post of John Spencer as it has a more in-depth explanation. This will only return the FIRST record oracle meets with minimal hiredate. It will not return more records if more than one employee has the same minimum hiredate.

    Published by: Centinul on October 23, 2009 09:38

  • Master &amp; detail table query

    My table structure
    create table company(
    co_id number(9) primary key,
    coname varchar2(32));
    
    create table co_location(
    co_id number(9) constraint location_fk references company(co_id),
    country varchar2(25));
    
    create table prod(
    co_id number(9) constraint prod_fk references company(co_id),
    prod_id number(14) primary key,
    prod varchar2(32));
    
    insert into company(co_id,coname) values(1,'ABC and Co');
    insert into co_location(co_id,country) values(1,'France');
    insert into prod(co_id,prod_id,prod) values(1,1,'aa');
    insert into prod(co_id,prod_id,prod) values(1,2,'bb');
    insert into prod(co_id,prod_id,prod) values(1,3,'cc');
    insert into prod(co_id,prod_id,prod) values(1,4,'aa');
    insert into prod(co_id,prod_id,prod) values(1,5,'ee');
    for example
    Company.Coname = "ABC and Co";
    co_location. Country = "France";
    Prod.Prod = "AA";

    I want to search 3 specific columns in the path:
     select a.co_id,coname,country,prod
     from
      company a, co_location b, prod c
     where
      a.co_id=b.co_id
     and
      a.co_id=c.co_id
     and
      coname='ABC and Co'
     and
      country='France'
     and
      prod='aa'
     /
    
    
         CO_ID CONAME                           COUNTRY                   PROD
    ---------- -------------------------------- ------------------------- ------------------------------
             1 ABC and Co                       France                    aa
    In this query, the problem is that company.coname and co_location.country is OK but prod creating problems as a co_id has much prod_id

    Thank you and best regards

    example with more than 1 column:

    SQL> ed
    Wrote file afiedt.buf
    
      1  select d.deptno, d.dname, e.empno, e.ename
      2  from emp e join dept d on (e.deptno = d.deptno)
      3* order by d.deptno, e.empno
    SQL> /
    
        DEPTNO DNAME               EMPNO ENAME
    ---------- -------------- ---------- ----------
            10 ACCOUNTING           7782 CLARK
               ACCOUNTING           7839 KING
               ACCOUNTING           7934 MILLER
            20 RESEARCH             7369 SMITH
               RESEARCH             7566 JONES
               RESEARCH             7788 SCOTT
               RESEARCH             7876 ADAMS
               RESEARCH             7902 FORD
            30 SALES                7499 ALLEN
               SALES                7521 WARD
               SALES                7654 MARTIN
               SALES                7698 BLAKE
               SALES                7844 TURNER
               SALES                7900 JAMES
    
    14 rows selected.
    
    SQL> break on deptno on dname
    SQL> select d.deptno, d.dname, e.empno, e.ename
      2  from emp e join dept d on (e.deptno = d.deptno)
      3  order by d.deptno, e.empno
      4  /
    
        DEPTNO DNAME               EMPNO ENAME
    ---------- -------------- ---------- ----------
            10 ACCOUNTING           7782 CLARK
                                    7839 KING
                                    7934 MILLER
            20 RESEARCH             7369 SMITH
                                    7566 JONES
                                    7788 SCOTT
                                    7876 ADAMS
                                    7902 FORD
            30 SALES                7499 ALLEN
                                    7521 WARD
                                    7654 MARTIN
                                    7698 BLAKE
                                    7844 TURNER
                                    7900 JAMES
    
    14 rows selected.
    
    SQL>
    
  • run wth params does not when used with table query Panel

    Hi Experts ADF,

    JDev 12 c

    I have a VO query that binds variables in which its clause. It also has a ViewCriteria who is dragged as a query with table Panel.

    When the loading of the page table does not display data.

    Click on the query search button, it works.

    Please let me know your opinion on this.

    Thank you

    Roy

    This is normal.

    You can replace it by initialQueryOverriden = true binary: display executed before the result of the query in a search engine

    Dario

  • Multi table query with key foreign null.

    Consider the following tables

    create table student (
     id number not null,
     name varchar2(80),
    primary key(id)
    );
    
    create table course(
      id number not null,
      subject varchar2(120),
      primary key(id)
    );
    
    create table class(
     id number not null,
     name varchar2(80),
     day number,
     course_id number not null,
     primary key(id),
     foreign key(course_id) references course(id)
    );
    
    create table student_course(
      id number not null,
      student_id number not null,
      course_id number not null,
      class_id number,
      primary key(id),
      foreign key(student_id) references student(id),
      foreign key(course_id) references course(id),
      foreign key(class_id) references class(id)
    );
    

    The student may enroll in a course and then a Professor assign to a class, that's why foreign class_id key isn't a constraint not null.

    What I want is to write a query so that the student can see all courses, it is registered for the class, that he has been assigned and the day of the class, but the report should include courses where the student is not assigned to a class again.

    I wrote the following query.

    select
     course.subject,
     class.name,
     class.day
    from
      course,
      class,
      student_course,
      student
    where course.id = student.course_id
    and class.id = student_course.class_id
    and student_course.foititis_id = get_foititis_id
    

    However, I only get the lines where the student_course.class_id is not null.

    I tried various combinations of coalesce, nvl, decode in both the select statement and where statement, but the results where garbage.

    No idea if such a request is possible?

    Thanks in advance for any help.

    Hello

    Thanks for posting the instructions CREATE TABLE.  Don't forget to display instructions INSERT for a litle sample data and the results desired from these sample data.

    odysam wrote:

    ... I wrote the following query.

    1. Select
    2. race. Subject,
    3. Class.Name,
    4. Class.Day
    5. Of
    6. Of course
    7. class,
    8. student_course,
    9. Student
    10. where course.id = student.course_id
    11. and class.id = student_course.class_id
    12. and student_course.foititis_id = get_foititis_id

    However, I only get the lines where the student_course.class_id is not null.

    I tried various combinations of coalesce, nvl, decode in both the select statement and where statement, but the results where garbage.

    No idea if such a request is possible? ...

    It's logical.  The condition on line 11

    Class.ID = student_course.class_id

    will not be TRUE is student.course.class_id is null.

    As Someoneelse said, looks like you need an Outer Join.

    Inner joins, as you use above, produce results only when a row in a table has one matching row in another table.

    In this case (as far as I can tell without data sample or results), you want to display the rows in a table with their matching rows When THERE is a MATCHING ROWS, but you want to show each row of the first table in any case, if corresponding lines.  This is an outer join.

Maybe you are looking for

  • With the help of check box in number to add/subtract a value of 0.5

    Hello I use a formula that calculates working hours daily and then subtract a half hour for lunch if a check box is selected. The formula applies with the exception of the time 0.5 being added or subtracted. Any ideas? The box strives to subtract the

  • Could not find the FPGA devices in Labview 20104 32bits

    Hi, I just installed Labview 2014 32 bit on my computer which also has 32-bit Labview 2012. The FPGA card is PCIe-7842R and the operating system is Windows 7 64 bit. The FPGA card works well on the 2012 LabVIEW. But in 2014, there not the target elem

  • Solution Center and Windows 8.

    I have upgraded to Windows 8 recently on my computer HP Omni 27-1054. The solution Center has stopped working. So, I found HP printer Installation Wizard. The wizard downloaded the necessary software, my old software uninstalled and installed the new

  • E4200 reset problem

    As I have not used this router Age, I couldn't remember the password to the router, or if I could locate my drive, I installed the E4200 v2 installation exe file and held the reset on the back for 10 seconds to reset the modem. I'm going by appropria

  • "Devices and printers" is empty, crashes, empty

    Hi all: Sincerely, I apologize if my problem has been resolved already.  As the title says, when I opened Orb-> devices and printers he always appears empty. I tried every associated bluetooth post, including the upgrade of drivers, check the BT serv