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 1030671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:44:18+00:00 2026-05-16T12:44:18+00:00

Note that I’m a complete SQL noob and in the process of learning. Based

  • 0

Note that I’m a complete SQL noob and in the process of learning. Based on Google searches (including searching here) I’ve tried using SELECT DISTINCT and GROUP BY but neither works, likely due to all of my joins (if anyone knows why they won’t work exactly, that would be helpful to learn).

I need data from a variety of tables and below is the only way I know to do it (I just know the basics). The query below works fine but shows duplicates. I need to know how to remove those. The only hint I have right now is perhaps a nested SELECT query but based on research I’m not sure how to implement them. Any help at all would be great, thanks!

USE SQL_Contest
go
SELECT
    CLT.Description AS ClockType,
    CLK.SerialNumber AS JobClockSerial,
    SIT.SiteNumber AS JobID,
    SIT.[Name] AS JobsiteName,
    SIT.Status AS SiteActivityStatus,
    DHA.IssuedDate AS DHAIssuedDate, -- Date the clock was assigned to THAT jobsite
    CLK.CreatedDate AS CLKCreatedDate, -- Date clock first was assigned to ANY jobsite
    SES.ClockVoltage
FROM tb_Clock CLK
INNER JOIN tb_ClockType CLT
ON CLK.TypeID = CLT.ClockTypeID
INNER JOIN tb_DeviceHolderActivity DHA
ON CLK.ClockGUID = DHA.DeviceGUID
INNER JOIN tb_Site SIT
ON SIT.SiteGUID = DHA.HolderGUID
LEFT JOIN tb_Session SES
ON SES.ClockSerialNumber = CLK.SerialNumber
WHERE DHA.ReturnedDate IS NULL
ORDER BY SIT.[Name] ASC

EDIT: I will be reviewing these answers shortly, thank you very much. I’m posting the additional duplicate info per Rob’s request:

Everything displays fine until I add:

LEFT JOIN tb_Session SES
ON SES.ClockSerialNumber = CLK.SerialNumber

Which I need. That’s when a duplicate appears:

JobClock 2,500248E4,08-107,Brentwood Job,1,2007-05-04 13:36:54.000,2007-05-04 13:47:55.407,3049    
JobClock 2,500248E4,08-107,Brentwood Job,1,2007-05-04 13:36:54.000,2007-05-04 13:47:55.407,3049

I want that info to only display once. Essentially this query is to determine all active jobsites that have a clock assigned to them, and that job only has one clock assigned to it, and it’s only one jobsite, but it’s appearing twice.

EDIT 2: Based on the help you guys provided I was able to determine they actually are NOT duplicates, and each session is independent, that is the only one that happened to have two sessions. So now I’m going to try to figure out how to only pull in information from the latest session.

  • 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-05-16T12:44:19+00:00Added an answer on May 16, 2026 at 12:44 pm

    If everything “works fine” until you add:

    LEFT JOIN tb_Session SES
    ON SES.ClockSerialNumber = CLK.SerialNumber
    

    Then there must be more than one record in tb_Session for each CLK.SerialNumber.

    Run the following query:

    SELECT  *
    FROM    tb_Session SES
    WHERE   ClockSerialNumber = '08-107'
    

    There should be two records returned. You need to decide how to handle this (i.e. Which record do you want to use?), unless both rows from tb_Session contain identical data, in which case, should they?

    You could always change your query to:

    SELECT
        CLT.Description AS ClockType,
        CLK.SerialNumber AS JobClockSerial,
        SIT.SiteNumber AS JobID,
        SIT.[Name] AS JobsiteName,
        SIT.Status AS SiteActivityStatus,
        DHA.IssuedDate AS DHAIssuedDate, -- Date the clock was assigned to THAT jobsite
        CLK.CreatedDate AS CLKCreatedDate, -- Date clock first was assigned to ANY jobsite
        SES.ClockVoltage
    FROM tb_Clock CLK
    INNER JOIN tb_ClockType CLT
    ON CLK.TypeID = CLT.ClockTypeID
    INNER JOIN tb_DeviceHolderActivity DHA
    ON CLK.ClockGUID = DHA.DeviceGUID
    INNER JOIN tb_Site SIT
    ON SIT.SiteGUID = DHA.HolderGUID
    LEFT JOIN 
    (
        SELECT DISTINCT ClockSerialNumber, ClockVoltage
        FROM tb_Session 
    ) SES
    ON SES.ClockSerialNumber = CLK.SerialNumber
    WHERE DHA.ReturnedDate IS NULL
    ORDER BY SIT.[Name] ASC
    

    As that should ensure that SES only contains one record for each unique combination of ClockSerialNumber and ClockVoltage

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Note that I'm aware of other yield in vb.net questions here on SO. I'm
Note that I'm mirroring the example given here very closely. In fact, my situation
Please note that Hijack page scrolling like Google Plus? asks for a very different
Note that I'm not actually doing anything with a database here, so ORM tools
Please note that I have seen a similar query here , but think my
Edit : Note that my final purpose here is not having the class working,
please note that I'm a complete beginner to Qt development. I have a QWebView
* Please note that this is not for a web based application, it's windows
Update: note that the actual problem here wasn't with core data more with a
Note that the _src inherit IQueryable<U> and V inherit new() ; I wrote the

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.