Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2005
    Posts
    26

    Unanswered: Merging two tables then grouping them

    I have two tables, one is named Employee and the other Job_title. I'm trying to combine the two tables so I can group certain columns.

    This is what I thought of so far and please correct me if I'm wrong.

    SELECT Last_name FROM Employee
    UNION
    SELECT Job_title_code FROM Job_title
    GROUP BY Exempt_non_exempt
    FROM Job_title

    Now this is just a theory (obviously it doesn't work) but basiclly I'm trying to have columns from two tables and have the grouped.

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Huh?

    Wha?

    There is no relationship between these tables?
    No foreign keys?
    You are selecting a single column and performing GROUP BY without any aggregate functions?

    This makes no sense.
    If it's not practically useful, then it's practically useless.

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

  3. #3
    Join Date
    Jan 2005
    Posts
    26
    Well, in both tables, they each have a job_title_code column.

    Employee table
    lastname, firstname, job title code

    Job_title Table
    job title code, job title, salary, exempt/non exempt

  4. #4
    Join Date
    Jan 2004
    Location
    In a large office with bad lighting
    Posts
    1,040
    Is this homework?

    It looks like homework.
    It sounds like homework.

    Are we studying relational databases?

  5. #5
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    So why aren't you using a join?

    Code:
    SELECT	Last_name,
    	Job_title_code,
    	Exemp_non_exempt
    FROM	Employee
    	INNER JOIN Job_title on Employee.Job_title_code = Job_title.Job_title_code
    I don't think this is homework. If it was homework his question would be more clearly phrased!
    If it's not practically useful, then it's practically useless.

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

  6. #6
    Join Date
    Jan 2005
    Posts
    26
    sorry for the mix up, yes it is homework. that's for suggesting the INNER JOIN command. i found a variation of what you did and it worked out for my db. by the way, how did you put your code in a window like that?

    SELECT Employee.Last_Name, Job_title.Exempt_non_exempt_status
    FROM Employee
    INNER JOIN Job_title
    ON Employee.Job_title_code=Job_title.Job_title_code

  7. #7
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Enclose your code in CODE tagsL

    [XCode]
    Your code here
    [X/Code]

    Remove the X characters...

    Code:
    Your code 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
  •