Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8793653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:09:00+00:00 2026-06-13T23:09:00+00:00

I have the following two tables: lab_assistant la_id – la_firstname – la_lastname 1 –

  • 0

I have the following two tables:

lab_assistant
la_id - la_firstname - la_lastname
1 - Dennis - Rodman
2 - Michael - Jordan
3 - Horace - Grant

hours_worked
hw_semester - hw_date - hw_hours - la_id
Fall 2012 - 2012-11-01 - 4 - 2
Fall 2012 - 2012-11-04 - 5 - 3
Spring 2012 - 2012-02-12 - 4 - 1
Spring 2012 -2012-03-10 - 4 - 1

The result of my query is supposed to look like the following:

and I’m trying to run the following query in order to list the Lab Assistant and the number of hours they worked each semester

SELECT DISTINCT(CONCAT(la.la_firstname, ' ', la.la_lastname)) AS 'Lab Assistant',
   hw.hw_semester AS 'Semester Worked', hw.hw_hours AS 'Hours Worked'
FROM lab_assistant la
    JOIN hours_worked hw
        ON la.la_id = hw.la_id;

The results of my quere are SUPPOSED to look like this:

Michael Jordan - Fall 2012 - 4
Horace Grant - Spring 2012 - 5
Dennis Rodman - Fall 2012 - 8

BUT the results I’m getting are as follows:

Michael Jordan - Fall 2012 - 4
Horace Grant - Fall 2012 - 5
Dennis Rodman - Spring 2012 - 4

So basically, it just isn’t counting the proper hours for Dennis Rodman. It should be 8 and not 4.

And I probably shouldn’t use DISTINCT here because it’s possible the same person could work different semesters.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:09:01+00:00Added an answer on June 13, 2026 at 11:09 pm

    DISTINCT needs to go at the beginning of the SELECT:

    SELECT DISTINCT CONCAT(la.la_firstname, ' ', la.la_lastname) AS 'Lab Assistant',
        hw.hw_semester, COUNT(w.hw_hours)
    FROM lab_assistant la
        JOIN hours_worked hw
            ON la.la_id = hw.la_id;
    

    But since you are using aggregate functions, you will want to use GROUP BY:

    SELECT CONCAT(la.la_firstname, ' ', la.la_lastname) AS 'Lab Assistant',
        hw.hw_semester, COUNT(w.hw_hours)
    FROM lab_assistant la
        JOIN hours_worked hw
            ON la.la_id = hw.la_id
    GROUP BY hw.hw_semester;
    

    Based on your edit, you need something like this:

    SELECT CONCAT(la.la_firstname, ' ', la.la_lastname) AS 'Lab Assistant',
      hw.hw_semester AS 'Semester Worked', 
      sum(hw.hw_hours) AS 'Hours Worked'
    FROM lab_assistant la
    JOIN hours_worked hw
      ON la.la_id = hw.la_id
    GROUP BY la.la_id, hw.hw_semester;
    

    See SQL Fiddle with Demo

    Results:

    |  LAB ASSISTANT | SEMESTER WORKED | HOURS WORKED |
    ---------------------------------------------------
    |  Dennis Rodman |     Spring 2012 |            8 |
    | Michael Jordan |       Fall 2012 |            4 |
    |   Horace Grant |       Fall 2012 |            5 |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following two tables in my mysql database. Table Name: groups id
I have the following two tables Groups Id (int) People Id (int) GroupId (int,
I have the following two tables, affiliates and referrers. affiliates Table id loginid 3
I have the following two tables: Customer { int Id int Name } Bills
I have the following two tables: Table1 ---------- ID Name 1 A 2 B
1I have the following two tables (sample data) and need to be able to
I have the following two tables: auth_user id username is_active (boolean) ... useprofile_userprofile id
Say for example, I have the following two tables: TableA { _id } TableB
For example, let's say I have the following two tables: Table1: Id ---- 1
I am using VB.NET with LINQ to MS SQL. I have two following tables.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.