Results 1 to 10 of 10
  1. #1
    Join Date
    Oct 2012
    Posts
    2

    Unanswered: how to write sql query to find manager name from employee table without Joins

    table structure is very simple as below and I know there are solutions with joins (Left outer joins), need to know if it is possible to get o/p without using joins
    Note:- also need records who doesn't have manager (null)

    table structure
    eid------ename------mgrid
    1------Nancy------2
    2------Andrew------null
    3------Janet ------2
    4------Margaret------2
    5------Steven------4
    6------Michael ------5

    o/p
    Employee------Manager
    Nancy------Andrew
    Andrew------Null
    Janet ------Andrew
    .
    .

  2. #2
    Join Date
    Apr 2012
    Posts
    213
    I think it would be better to use Left Join but follows another alternative:

    Code:
    select 
        e.eid, 
        e.ename, 
        e.mgrid, 
        (select m.Manager from Managers where m.Employee = e.ename) as Manager
    from Employees as e
    Hope it's useful.

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by shankar.mp View Post
    ... without using joins
    what the heck is wrong with using joins??!!!
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Sep 2001
    Location
    Chicago, Illinois, USA
    Posts
    601
    When I work on my car, I have a rule . . . use no tools.

    I only use my fingers.

    Unscrewing lug nuts that have been tightened with an impact wrench can be a lot of fun, and the blood flowing from my fingers makes the slippery process that much more difficult.

    But at least I can say that I can work on my car without tools.
    Ken

    Maverick Software Design

    (847) 864-3600 x2

  5. #5
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Quote Originally Posted by r937 View Post
    what the heck is wrong with using joins??!!!
    If I had to offer a guess, I'd assume that the teacher will give extra credit for finding a solution that doesn't require a JOIN beause that requires non-standard coding and a bit more expertise. Of course, there could be another reason, but I'll be dipped if I can think of a good one!

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  6. #6
    Join Date
    Oct 2009
    Location
    221B Baker St.
    Posts
    486
    The ever-popular "That's the requirement" . . .

  7. #7
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Perhaps his "J" key doesn't work consistently?

    Shankar, here are some "J"s you can copy and paste:
    JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
    Let me know if you need any more.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  8. #8
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by imex View Post
    ... but follows another alternative
    me too
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  9. #9
    Join Date
    Oct 2012
    Posts
    2
    this is one of the questions in an online exam and not a joke/story/heck i wana here

    as said by PatP, it requires bit more expertise.....which I don't have and asked for in this forum

    If I get that expertise and solution, I will post in this forum

    -Thx

  10. #10
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    IMEX gave you a solution.
    Its a bad solution, but only because the requirements were bad.
    What online exam are you taking that has questions like "Write crappy SQL."?
    Don't take the joshing personally. We just kid around a lot on here.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •