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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:02:10+00:00 2026-06-01T03:02:10+00:00

Normally I would do select top (1) * from table where id active =

  • 0

Normally I would do

select top (1) * from table where id active = '1' and doc_type_id = '404'

to get the latest row.

However I’m using IN to get results back. Plus a join.

select t1.* 
  from table1 t1 left join table2 t2 on (t1.propid = t2.propid)
 where t2.caseid in ('100','101') and t1.active = '1' and b.doc_type_id = '404'

This query here returns the documents. However there are multiple documents of the same type.
And if each one has 10 docs I need only the latest one.

I would want to retrieve only the latest 1 doc for each from the database.

I hope I explained myself 🙂

  • 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-01T03:02:12+00:00Added an answer on June 1, 2026 at 3:02 am

    Without seeing the return types you are going for, it sounds like you need to use a GROUP BY and/or a MAX. If that does not help solve your problem, could you please post a sample data set and what you expect?

    You might even be able to use partitioning and/or ROW_NUMBER()

    UPDATE BASED ON COMMENTS

    WITH myCTE
    AS
    (
        SELECT t1.*, 
            ROW_NUMBER() OVER (PARTITION BY t2.caseid ORDER BY LastSavedDate DESC) AS RowNumber
        FROM table1 t1 
            LEFT JOIN table2 t2 
                ON t1.propid = t2.propid
        WHERE t2.caseid in ('100','101') 
            AND t1.active = '1' AND b.doc_type_id = '404'
    )
    SELECT * 
    FROM myCTE
    WHERE RowNumber = 1;
    

    This MIGHT work for you based on your comments

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

Sidebar

Related Questions

Normally you can do this: <select size=3> <option>blah</option> <option>blah</option> <option>blah</option> </select> And it would
Normally I would just use URL GET parameters but CodeIgniter doesn't seem to like
I would normally use: if ($(#parkState).val() == 0) { alert(Please select a state.); }
One would normally have this query in their sphinx.conf file : sql_query = SELECT
I have some data in a dataset and I would normally select a record
It am trying to launch this code that would normally run from a batch
$sql = 'SELECT * FROM `phpbb_profile_fields_data`'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) {
Normally I would put the data type into a temp table and inspect the
Possible Duplicate: How to get all options of a select using Jquery? I have
I want to be able to take any arbitrary SELECT TOP(X) query that would

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.