If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Help with mysql, PLEASE

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-22-09, 16:45
Antonioj1015 Antonioj1015 is offline
Registered User
 
Join Date: Aug 2009
Posts: 13
Question 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::..
Reply With Quote
  #2 (permalink)  
Old 08-22-09, 19:10
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Code:
SELECT DISTINCT Boss.Name
  FROM Employees AS Empl
INNER
  JOIN Employees AS Boss
    ON Boss.Doc = Empl.Boss
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 08-24-09, 20:21
Antonioj1015 Antonioj1015 is offline
Registered User
 
Join Date: Aug 2009
Posts: 13
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::..
Reply With Quote
  #4 (permalink)  
Old 08-26-09, 02:04
micky126 micky126 is offline
Registered User
 
Join Date: Aug 2009
Posts: 8
have youy tried the statement that you have posted? or r937 posted? What's the resultset look like?
Reply With Quote
  #5 (permalink)  
Old 08-26-09, 13:20
Antonioj1015 Antonioj1015 is offline
Registered User
 
Join Date: Aug 2009
Posts: 13
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::..
Reply With Quote
  #6 (permalink)  
Old 08-26-09, 13:33
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
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?

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 08-26-09, 13:38
Antonioj1015 Antonioj1015 is offline
Registered User
 
Join Date: Aug 2009
Posts: 13
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::..
Reply With Quote
  #8 (permalink)  
Old 08-26-09, 13:43
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 08-26-09, 14:14
Antonioj1015 Antonioj1015 is offline
Registered User
 
Join Date: Aug 2009
Posts: 13
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::..
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On