Results 1 to 3 of 3
  1. #1
    Falcom is better than SE. Change my mind.
    Join Date
    Jun 2006
    Posts
    17,291
    BG Level
    9

    Anyone here good with SQL?

    I have an SQL assignment due tonight and nearly done with it, but one question is bothering the hell out of me.

    The question is:

    Still using Oracle join syntax, alter the previous query so that it also includes the employee record of the employee with no department_id, „Grant‟.

    This is the code I have:

    SELECT e.last_name, d.department_name, e.salary, c.country_name
    FROM dept d, emp e, countries c, locations l
    WHERE d.department_id = e.department_id
    AND c.country_id = l.country_id
    AND d.location_id = l.location_id;


    Now other than I probably could have done a better job on the statement, the problem is I can't figure out where to do an outer join. It seems like I should do an outer join on d.department_id, but when I nothing happens unless I remove the last line of code, but that leaves me with a partial Cartesian result.

    Crappy pic of what the result SHOULD look like:
    http://i47.tinypic.com/o9idyu.png

  2. #2
    MOST RAD.
    Join Date
    Oct 2007
    Posts
    1,664
    BG Level
    6
    FFXIV Character
    Pupuru Puru
    FFXIV Server
    Goblin
    FFXI Server
    Ragnarok

    Maybe: FROM countries c, locations l, emp e left outer join dept d on d.department_id=e.department_id?

  3. #3
    Falcom is better than SE. Change my mind.
    Join Date
    Jun 2006
    Posts
    17,291
    BG Level
    9

    No dice, it looks like it has to be an outer join on the d.department_id so it should look something like this:

    SELECT e.last_name, d.department_name, e.salary, c.country_name
    FROM dept d, emp e, countries c, locations l
    WHERE d.department_id(+) = e.department_id
    AND c.country_id = l.country_id
    AND d.location_id = l.location_id;


    But that d.location_id is what seems to be causing the problem, I can't outer join that to since all that does is cause an error, and I can't remove it either.

Similar Threads

  1. Anyone good with video encoding!? :P
    By Gulkeeva in forum Tech
    Replies: 8
    Last Post: 2009-06-07, 21:07
  2. Replies: 19
    Last Post: 2007-03-12, 18:18