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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:44:41+00:00 2026-06-17T15:44:41+00:00

I have this query: SELECT DISTINCT enc.id, enc.cus_id, enc.createdon, enc.status, enc.segment, enc_task.orderid, enc_task.taskid, enc.currentstep,

  • 0

I have this query:

SELECT DISTINCT 
    enc.id, enc.cus_id, enc.createdon, enc.status, enc.segment, enc_task.orderid, 
    enc_task.taskid, enc.currentstep, enc.groupid, enc.fdprotocol, 
    enc_task.linkfile, cus.fname, cus.lname, login.first_name, login.last_name, 
    login.username, login.user_code, login.id as assigned_id, fp.protocol, 
    init.typename, table4.allowtotal 
FROM 
    mob_encounters enc 
    JOIN mob_encounters_task enc_task ON enc_task.encounterid=enc.id
    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
    LEFT JOIN initiation_type init ON init.id=enc.groupid
    LEFT JOIN mob_table4 table4 ON table4.encid=enc.id

GROUP BY 
    enc.id

The query is working, except I need it to return the latest row of enc_task.encounterid when doing this match: enc_task.encounterid = enc.id. Is it possible?

  • 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-17T15:44:43+00:00Added an answer on June 17, 2026 at 3:44 pm

    A subquery might do what you’re looking for:

    SELECT DISTINCT 
                    enc.id, enc.cus_id, enc.createdon, enc.status, enc.segment, enc_task.orderid, enc_task.taskid,
                    enc.currentstep, enc.groupid, enc.fdprotocol, enc_task.linkfile, cus.fname, 
                    cus.lname, login.first_name, login.last_name, login.username, login.user_code,
                    login.id as assigned_id, fp.protocol, init.typename, table4.allowtotal 
                FROM 
                    mob_encounters enc 
                JOIN 
                    (select encounterid, orderid, taskid, linkfile from mob_encounters_task order by [FIELD THAT DESIGNATES LATEST VALUE] desc) AS enc_task ON enc_task.encounterid=enc.id
                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
                LEFT JOIN 
                    initiation_type init ON init.id=enc.groupid
                LEFT JOIN 
                    mob_table4 table4 ON table4.encid=enc.id
                GROUP BY 
                    enc.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query: SELECT DISTINCT IM.EDIFICIOS_ID, TI.TITULAR FROM IMPORTACION IM INNER JOIN I_EDIFICIO
I have this SQL query: SELECT DISTINCT tb.SERIAL_NUM, tb.REVISION_NUM, tb.JOB_NUM, tb.JOB_TOTAL, tb.TEST_PROC, tb.BOX_NUM, tb.TEST_BENCH,
I have this query... SELECT Distinct([TargetAttributeID]) FROM (SELECT distinct att1.intAttributeID as [TargetAttributeID] FROM AST_tblAttributes
I have managed to bring the following output with this query SELECT DISTINCT IF(purchaseproduct_customerid=0,contactperson,vendorname)
I have a mysql query like this: $topicreplycount = mysql_query('SELECT COUNT(DISTINCT post_msg_id) FROM phpbb_attachments
This is a simpler version of the query I have. Alias1 as (select distinct
I have this SQL Server query SELECT count(distinct [IP]) as GlobalUniqueIPcount, --RangeUniqueIPcount (SELECT count(distinct
I have this query that uses a UNION: $this->db->query(' SELECT DISTINCT users.user_pic, users.id, users.username,
If I have this SQL query: select distinct top 1 'PostId' = isnull(RootPost,Id), PostedDateTimeUtc
I have this query: select distinct pdi.height, pdi.width, pj.jobnum , (select count(barcode) from productiondoorinformation

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.