Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2009
    Posts
    18

    Question Unanswered: Help with mysql, PLEASE

    heres the thing, i made a table named Employees
    +----------+-------------+------+-----+---------+-------+
    | Field | Type | Null | Key | Default | Extra |
    +----------+-------------+------+-----+---------+-------+
    | Doc | varchar(5) | NO | PRI | NULL | |
    | Name | varchar(20)| NO | | NULL | |
    | Salary | varchar(7) | NO | | NULL | |
    | City | varchar(10)| NO | | NULL | |
    | Boss | varchar(5) | YES| | NULL | |
    +----------+-------------+------+-----+---------+-------+
    In this table theres Doc (which is document and the primary key) of the employee, the name of the employee, the salary of the employee, the city in which the employee is at, and the boss which is the Doc.
    so i put some info in and it looks like this:
    +-------+----------+---------+----------+-------+
    | Doc | Name | Salary | City | Boss |
    +-------+----------+---------+----------+-------+
    | 10305 | Joey | 700 | NYC | NULL |
    | 10244 | John | 900 | Boston | 10305 |
    | 35357 | Mary | 600 | Boston | 10305 |
    | 90012 | Becky | 650 | Miami | 35357 |
    +-------+----------+---------+----------+-------+
    as you can see Joey is the boss of John and Mary, And Mary is the boss of becky.
    How can i make that only the bosses appear, like for Joey and Mary to be the only ones to show?
    i tried it like this but no luck:
    select Name from employees where Doc = (SELECT Boss FROM employees);
    ..::Antonioj1015::..

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT DISTINCT Boss.Name
      FROM Employees AS Empl
    INNER
      JOIN Employees AS Boss
        ON Boss.Doc = Empl.Boss
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Aug 2009
    Posts
    18
    Quote Originally Posted by r937
    Code:
    SELECT DISTINCT Boss.Name
      FROM Employees AS Empl
    INNER
      JOIN Employees AS Boss
        ON Boss.Doc = Empl.Boss
    Come on man please help me with the other question i got at least one, and if its too much to ask could you explain me this one, please please please..
    ..::Antonioj1015::..

  4. #4
    Join Date
    Aug 2009
    Posts
    8
    have youy tried the statement that you have posted? or r937 posted? What's the resultset look like?

  5. #5
    Join Date
    Aug 2009
    Posts
    18
    Quote Originally Posted by micky126
    have youy tried the statement that you have posted? or r937 posted? What's the resultset look like?
    well i ahevnt because i have sent r937 to explain me this one but no results, cif you can could you explain it to me? thanks...
    ..::Antonioj1015::..

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by Antonioj1015
    well i ahevnt because i have sent r937 to explain me this one but no results
    you need an explanation to test it? no

    you need an explanation in order to turn it in as your homework answer? yes

    okay, here is the explanation --

    bosses are those people (Employees AS Boss) to whom other people (Employees AS Empl) report (INNER JOIN ON Boss.Doc = Empl.Boss)

    simple, eh?

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  7. #7
    Join Date
    Aug 2009
    Posts
    18
    Quote Originally Posted by r937
    you need an explanation to test it? no

    you need an explanation in order to turn it in as your homework answer? yes

    okay, here is the explanation --

    bosses are those people (Employees AS Boss) to whom other people (Employees AS Empl) report (INNER JOIN ON Boss.Doc = Empl.Boss)

    simple, eh?

    one, yes its for homework
    two, i prefer to learn about the "copy" i did than turn something in and forget it and never know how it was done, but anyways thanks for the explanation and i already solved one of the other two:
    SELECT * from employees where Doc In (SELECT Boss from employees group by Boss having count(*) > 1);
    i'm still working on the second one, and if its not much to ask what does DISTINCT do? i search on internet but i dont understand, Thanks anyways...
    ..::Antonioj1015::..

  8. #8
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by Antonioj1015
    and if its not much to ask what does DISTINCT do?
    what do ~you~ think it does?

    google "SQL tutorial" (there's only, like, a bazillion of them) and look under the SELECT statement

    if the SQL tutorial you chose does not explain SELECT DISTINCT, move on to the next one

    you'll find it pretty soon
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  9. #9
    Join Date
    Aug 2009
    Posts
    18
    Quote Originally Posted by r937
    what do ~you~ think it does?

    google "SQL tutorial" (there's only, like, a bazillion of them) and look under the SELECT statement

    if the SQL tutorial you chose does not explain SELECT DISTINCT, move on to the next one

    you'll find it pretty soon
    hey its so the name of the boss doent appear more than one, if 2 or more rows are the same he only puts one, its like so they dont repeat, i just removed it from the code and it showed me the name of a boss 2 times, thanks man and sorry for all the questioning...
    ..::Antonioj1015::..

Posting Permissions

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