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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:22:40+00:00 2026-05-11T22:22:40+00:00

Query: SELECT DISTINCT ([Equipment List].ID) AS Expr1, [Job Assignments].Job FROM [Equipment List] LEFT JOIN

  • 0

Query:

SELECT DISTINCT ([Equipment List].ID) AS Expr1, [Job Assignments].Job
FROM [Equipment List] LEFT JOIN [Job Assignments] 
    ON [Equipment List].ID = [Job Assignments].EquipmentID;

In this query, the equipment ID is distinct if and only if I do not add the [Job Assignments].Job in the select statement. As soon as I do, I get many duplicates. The Job Assignments table has many jobs, but I am only interested in the one with the [Date Returned] blank or null. Any ideas how to accomplish this? I am using this as a report, so It gives me an error when I try to use inner sql queries. Also this is a simplified query, as the original has multiple selects. What am I doing wrong? Any help would be greatly appreciated.

Update: I am looking to select only one row from [Job Assignments] Table. Any ideas?

  • 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-11T22:22:41+00:00Added an answer on May 11, 2026 at 10:22 pm

    DISTINCT returns distinct combinations of all columns in the SELECT statement, which is why introducing a second column also introduces dupes.

    It sounds like you can get away with a WHERE clause:

    SELECT DISTINCT ([Equipment List].ID) AS Expr1, [Job Assignments].Job 
    FROM [Equipment List] 
    LEFT JOIN [Job Assignments] ON [Equipment List].ID = [Job Assignments].EquipmentID
    WHERE [Job Assignments].[Date Returned] IS NULL
    

    You can’t have a “blank” date, so if you’re seeing blanks then chances are you’re not using a datetime type to store your date – in this case, you’ll need to say:

    WHERE COALESCE([Job Assignments].[Date Returned], '') = ''
    

    Edit: Latest solution based on comments below:

    ;WITH LatestJobs
    AS
    (SELECT     ja.EquipmentID, ja.Job,
                ROW_NUMBER() OVER ( PARTITION BY EquipmentID 
                                    ORDER BY [Date Returned] DESC) AS RowNumber
    FROM        [Job Assignments] AS ja)
    
    SELECT      el.ID AS EquipmentID, 
                lj.Job
    FROM        [Equipment List] AS el
    LEFT JOIN   LatestJobs AS lj ON el.ID = lj.EquipmentID
                AND lj.RowNumber = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this query: SELECT DISTINCT pat.PublicationID FROM dbo.PubAdvTransData AS pat INNER JOIN
I have this query: SELECT DISTINCT IM.EDIFICIOS_ID, TI.TITULAR FROM IMPORTACION IM INNER JOIN I_EDIFICIO
Given the query: SELECT DISTINCT score.* FROM score LEFT OUTER JOIN tag ON (tag.id_score
This is my current query: SELECT DISTINCT t.* FROM filter AS f INNER JOIN
I'm using this query to list duplicate records SELECT DISTINCT column1 from table group
So I have this query: SELECT DISTINCT(b.friend_id) AS possible_id FROM friend_friends a JOIN friends_friends
I have this query: SELECT DISTINCT(b.friend_id) AS possible_id FROM friends_friends a JOIN friends_friends b
I have the following query: SELECT DISTINCT w.name, count(*) FROM widgets AS w JOIN
I have a mysql query like this: $topicreplycount = mysql_query('SELECT COUNT(DISTINCT post_msg_id) FROM phpbb_attachments
I have an oracle sql query select distinct tab1.col1, tab2.col1 from table1 tab1 join

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.