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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:35:57+00:00 2026-06-17T13:35:57+00:00

I have this medium-sized query and I am having some problems getting certain fields.

  • 0

I have this medium-sized query and I am having some problems getting certain fields.

SELECT DISTINCT 
  enc.id, enc.cus_id, enc.createdon, enc.status, 
  enc.segment, enc.currentstep, enc.groupid, enc.fdprotocol, 
  enc_task.linkfile, cus.fname, cus.lname, login.first_name, 
  login.last_name, login.username, login.user_code, fp.protocol 
FROM
  mob_encounters_task enc_task, mob_encounters enc, 
  mob_customer cus, mob_login login, mob_protocol_type fp 
WHERE 
  enc.id=enc_task.encounterid 
AND 
  cus.id=enc_task.cus_id 
AND 
  login.id=enc.createdby 
GROUP BY enc.id

fp.protocol is a string, and on the table fp there are up to 5 or 6 “protocols”.

what I wanted to do is if enc.fdprotocol is empty then fp.protocol should be empty, otherwise get the fp.protocol associated to the fp.id= enc.fdprotocol

Please let me know if this sounds confusing, I have been stuck on this for some time

  • 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-17T13:35:58+00:00Added an answer on June 17, 2026 at 1:35 pm

    I find that using the actual JOIN syntax makes queries much more readable and maintainable. In this case you need to use a LEFT JOIN and you have to change your syntax for that:

    SELECT enc.id, enc.cus_id, enc.createdon, enc.status, enc.segment, 
    enc.currentstep, enc.groupid, enc.fdprotocol, enc_task.linkfile, cus.fname, 
    cus.lname, login.first_name, login.last_name, login.username, login.user_code, 
    fp.protocol 
        FROM mob_encounters_task enc_task
        JOIN mob_encounters enc ON enc.id=enc_task.encounterid
        JOIN mob_customer cus ON cus.id=enc_task.cus_id
        JOIN mob_login login ON login.id=enc.createdby 
        LEFT JOIN mob_protocol_type fp ON fp.id = enc.fdprotocol
    

    Also I don’t believe you need DISTINCT

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

Sidebar

Related Questions

Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt
Some background: I have what I would consider a medium-sized GWT app deployed to
For background, I have come across this porting a medium-sized linux codebase (compiling into
I have this json string: $row['medium'] = {\medium\:13|17|1|14, \medium_sub\:21}; now I want to make
I have this code <a href=#> <span style=border-right: medium none; class=Yes>Yes</span> </a> <a href=#>
I have this VM with tomcat, java, and grails in it. I've been getting
I've got this medium-sized app that is starting to get too complex. I'm considering
I have taken over a medium sized project that was written originally using RoR.
First, I only have experience building small-medium sized websites with php so forgive me
We have a medium sized application that depends on several usercontrols, namely: A tablelayout

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.