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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:51:54+00:00 2026-05-14T05:51:54+00:00

The scenario: Table1 CatId|Name|Description Table2 ItId|Title|Date|CatId (foreign key) I want to return all rows

  • 0

The scenario:

Table1
CatId|Name|Description

Table2
ItId|Title|Date|CatId (foreign key)

I want to return all rows from Table1 and Title,Date from Table2, where
The returned from Table 2 must be the Latest one by the date column.
(in second table there many items with same CatId and I need just the latest)

I have 2 queries but can’t merge them together:

Query 1:  
SELECT Table1.Name,  Table1.Description,
       Table2.Title, Table2.Date
FROM 
       Table1 LEFT JOIN Table2 ON Table1.CatId=Table2.CatId

Query2:

SELECT TOP 1 Table2.Title, Table2.Date
FROM 
    Table2
WHERE 
    Table2.CatId = @inputParam
ORDER BY Table2.Date DESC
  • 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-05-14T05:51:55+00:00Added an answer on May 14, 2026 at 5:51 am

    Sounds like you’re talking about a groupwise maximum (newest row in Table2 for each matching row in Table1), in which case, the easiest way is use ROW_NUMBER:

    WITH CTE AS
    (
        SELECT
            t1.Name, t1.Description, t2.Title, t2.Date,
            ROW_NUMBER() OVER (PARTITION BY t1.CatId ORDER BY t2.Date DESC) AS Seq
        FROM Table1 t1
        LEFT JOIN Table2 t2
            ON t2.CatId = t1.CatId
    )
    SELECT *
    FROM CTE
    WHERE Seq = 1
    OR Date IS NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SCENARIO: I have two tables, table1(col1 date) and table2(col2 varchar(20)). REQUIREMENT: Whenever anyone updated
Consider the following MySQL scenario: Table1: id, date, value Table2: id, month, count Table
I have a scenario like this: There are two tables table1 and table2 .
Scenario: I need to list all the columns in a table1 and all stored
Here is the scenario: I want to sort names in table1 according to ages
Simple scenario: table view controller, with 5.000 rows. I have 5000 images name from
Scenario: I have a table1(col1 char(5)); A value in table1 may '001' or '01'
Scenario: Table A MasterID, Added Date, Added By, Updated Date, Updated By, 1, 1/1/2010,
Here is my scenario (Tables): Orders ====================== Id (int) description (varchar) Products ====================== Id
Here is my scenario (tables): Departments ==================== Id (int) Name (varchar) Employees ==================== Id

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.