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

  • Home
  • SEARCH
  • 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 8146409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:59:13+00:00 2026-06-06T13:59:13+00:00

Wondering if someone could please explain the difference between these two queries and advise

  • 0

Wondering if someone could please explain the difference between these two queries and advise why one works and the other doesn’t.

This one works. Gives me two records of the distinct GantryRtn value and their corresponding SSD value.

SELECT DISTINCT GantryRtn as Gantry, ROUND(Field.SSD,1) as SSD
            FROM Field, PlanSetup, Course, Patient, Radiation
                    WHERE Field.RadiationSer=Radiation.RadiationSer
                        AND Radiation.PlanSetupSer=PlanSetup.PlanSetupSer
                        AND PlanSetup.CourseSer=Course.CourseSer
                        AND Course.PatientSer=Patient.PatientSer
                        AND Patient.PatientId='ZZZ456'
                        AND PlanSetup.PlanSetupId='F T1 R CHEST'

However there is a foreign key in the Field table that links to the primary key of another table that contains a plain text name for each field. I’d also like to extract that name (in a separate query if I have to) by pulling out this foreign key RadiationSer. But as soon as I put RadiationSer into the query, I lose my DISTINCT result.

SELECT DISTINCT GantryRtn as Gantry, ROUND(Field.SSD,1) as SSD, Field.RadiationSer
            FROM Field, PlanSetup, Course, Patient, Radiation
                    WHERE Field.RadiationSer=Radiation.RadiationSer
                        AND Radiation.PlanSetupSer=PlanSetup.PlanSetupSer
                        AND PlanSetup.CourseSer=Course.CourseSer
                        AND Course.PatientSer=Patient.PatientSer
                        AND Patient.PatientId='ZZZ456'
                        AND PlanSetup.PlanSetupId='F T1 R CHEST'

This second query gives me 7 records with non-distinct GantryRtn values.

Why does this happen??

I have investigated using GROUP BY but this slows the query down and appears to pull ALL GantryRtn’s out of the database (100s of records).

Thanks
Greg

  • 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-06T13:59:15+00:00Added an answer on June 6, 2026 at 1:59 pm

    The DISTINCT keyword applys to a result set (all fields) and not just to the first field.

    In your case:

    SELECT DISTINCT GantryRtn as Gantry, ROUND(Field.SSD,1) as SSD, Field.RadiationSer
    

    will return any records that are distinct (not the same) when taken together with Gantry, SSD, and RadiationSer

    So, you may have 7 records for the same Gantry and with different values for RadiationSer.

    If you’d like to first filter by distinct Gantry values you can accomplish that with a sub-query and an inner join but somehow you must settle on which RadiationSer value to use.

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

Sidebar

Related Questions

I am wondering if someone could explain how I can utilise tags in an
was wondering if someone could help with this one. This is the first time
I was wondering if someone could work this one out as I've been trying
I was wondering could someone please help me implemenrt this method whereas I dont
I have reached a problem and was wondering if someone could help me please.
I am wondering if someone could please help me convert a piece of PHP
I'm in a-level computing and I was wondering if someone could please tell me
I was wondering if someone could please help me with this: printf(Enter path for
I am really stuck and was wondering if someone could lend a hand please,
I was wondering if someone could explain there terms since I encounter them in

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.