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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:27:46+00:00 2026-06-17T09:27:46+00:00

I have two related tables. Table 1: recordid | OrderNumber | MobileNumber 1 |

  • 0

I have two related tables.

Table 1:
recordid | OrderNumber | MobileNumber
       1 | 1234        | 9999999999
       2 | 1234        | 9888888888
       3 | 1234        | 9777777777
       4 | 5433        | 9666666666
       5 | 1444        | 9555555555
       6 | 1444        | 9444444444
       7 | 1544        | 9333333333
       8 | 1632        | 9222222222


Table 2
recordid | modifiedon
       1 | 15/1/2013
       2 | 17/1/2013 
       3 | 13/1/2013
       4 | 10/1/2013
       5 | 16/1/2013
       6 | 01/1/2013 
       7 | 09/1/2013
       8 | 08/1/2013

what i want to do is get a unique set of OrderNumber and their corresponding MobileNumbers. If there is are more than one record for one OrderNumber, then the query should get OrderNumber and MobileNumber of the latest modified record.

So basically i should get the following result.

OrderNumber | MobileNumber
1234        | 9888888888
5433        | 9666666666
1444        | 9555555555
1544        | 9333333333
1632        | 9222222222

i have tried

select OrderNumber, MobileNumber from Table1 
where OrderNumber in 
(
   Select Distinct table1. rderNumber, table2.ModifiedOn 
   from Table1, Table2 
   group by table2.ModifiedOn desc
) 

This is urgent and I would be very greatly to receive quick responses.

  • 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-17T09:27:46+00:00Added an answer on June 17, 2026 at 9:27 am

    It’s easier with a CTE and ROW_NUMBER:

    WITH cte AS 
    (SELECT t1.ordernumber, 
            t1.mobilenumber, 
            RN = Row_number() 
                   OVER ( 
                     partition BY t1.ordernumber 
                     ORDER BY t2, modifiedon DESC) 
             FROM   table1 t1 
                    INNER JOIN table2 t2 
                            ON t1.recordid = t2.recordid) 
    SELECT ordernumber, 
           mobilenumber
    FROM   cte 
    WHERE  rn = 1 
    

    Apart from that, you had a DESC after a GROUP BY.

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

Sidebar

Related Questions

I have two tables that are related via a mapping table: keywords titles I
we have two related tables(inventory and inventoryLocalization) on Sql Server 2005. the first table's
I have two tables that are indirectly related by another table TableA - ID,
I have two tables that need to be related--a users table and an address_book
I have two related tables in my database: Page and Tag. One Page can
I have two tables related: DataEntered and Model DataEntered -currentModel Model One DataEntered can
I have two models, say Product and Bundle. products table is related to product_prices
i have two tables both are related with primary-foreign key ralation and i have
I have two tables, related by a common key. So TableA has key AID
I have two tables, activities and activity_tours . activities hasMany activity_tours and are related

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.