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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:19:03+00:00 2026-06-05T22:19:03+00:00

I have two quite large tables, let’s call them ‘authors’ and ‘articles’. Every row

  • 0

I have two quite large tables, let’s call them ‘authors’ and ‘articles’.
Every row in the ‘articles’ table is associated with a single author represented by the value in the ‘AuthorID’ field.

We have a page where we show a set of writers that match a certain criteria, and the first article that is associated with every single writer, ordered by the value of the ‘DatePublished’ field in the article.

This is currently achieved by executing multiple queries which turns out to be really slow especially when executed for a large set of authors. I’m not the expert on the subject but I’m pretty sure there is a way to get this data with a single statement which will be much more optimized than the current mess.

To put it in another way: (Think every function call as a single SQL query)

What we have now:

$authors = get_some_authors($criteria);
for each($author in $authors) {
    $author->lastArticle = get_latest_article_by_author($author_id);
}

What we need:

$authors_with_last_articles = get_some_authors_and_their_latest_articles($criteria);

We’re using MS SQL Server 9.0.

Hope I could explain the problem correctly. Thanks in advance for your help.

  • 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-05T22:19:05+00:00Added an answer on June 5, 2026 at 10:19 pm

    You could use an outer apply to implement for-each behavior:

    select  *
    from    Authors
    outer apply
            (
            select  top 1 *
            from    Articles
            where   Authors.ID = Articles.AuthorId
            order by
                    Articles.PublishDate desc
            ) as LastArticle
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to process a large table (2.5B records) row by row in order
I need an XML-serializable dictionary. Actually, I now have two quite different programs that
If I have two interfaces , both quite different in their purposes , but
I have two click-events, that are nearly similar, but not quite. I am wondering
I have two classes generated by LINQ2SQL both from the same table so they
I am working on a quite large C library that doesn't have any tests
I have a large amount of text in Mysql tables. I want to do
In MYSQL, from a pure performance perspective, if I have a table with large
I have a MySQL(innodb) table 'items' with the following characteristics Large number of rows,
I have a program where I'm a table of a decently large block of

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.