Couple of Oracle SQL Questions

Discussion in 'Databases' started by badger879, Jun 7, 2012.

  1. #1
    Hello,
    Really Struggling on a couple of things with Oracle and was wondering if anybody here could help me.

    First of all I have the following statement:
    SELECT ename
    FROM emp 
    WHERE job  NOT IN ('CLERK', 'ANALYST', 'SALESMAN');
    
    Code (markup):
    I need to think of another way to perform the same function, which is to give details of all employees who are not Clerks, Analysts or Salesment. I tried to have a mess around with NOT EXIST but just cannot get anything to work.

    Secondly I am trying to show a list of courses which no students are enrolled on. I thought the following may work
    
    
    SELECT COURSENAME AS Coursename
    FROM COURSE
    INNER JOIN STUDENT
    ON course.coursename = student.coursename
    GROUP BY coursename
    HAVING count(coursecode) >= 1;
    
    Code (markup):
    However that is not working I am getting the error
    I did try another way which ended up with it just displaying all the courses whatever number I changed the count to.

    Any ideas?
     
    Solved! View solution.
    badger879, Jun 7, 2012 IP
  2. #2
    You could just do:
    WHERE job <> 'CLERK'
    AND job <> 'ANALYST'
    etc...

    It's uglier but is the same function.

    On the second, I would first double check that coursename is a valid column in the student table.

    Secondly, I would explicitly specify which coursename you are referring to in the query. It's ambiguous all over the place as to which coursename you mean.

    Should be:
    SELECT course.coursename AS Coursename 
    FROM   course 
           inner join student 
                   ON course.coursename = student.coursename 
    GROUP  BY course.coursename 
    HAVING Count(course.coursecode) >= 1; 
    Code (markup):
     
    jestep, Jun 7, 2012 IP
    badger879 likes this.
  3. badger879

    badger879 Well-Known Member

    Messages:
    145
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    130
    #3
    Thank you very much! Managed to work it out with a bit of tweaking.

    You have been a great help!
     
    badger879, Jun 8, 2012 IP