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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:15:26+00:00 2026-05-23T07:15:26+00:00

I have 3 tables Table1 Primary_key int Forign_key int PostId CreatedDate Datetime Table2 Primary_key

  • 0

I have 3 tables

Table1

Primary_key  int
Forign_key  int
PostId
CreatedDate Datetime

Table2

Primary_key int
Forign_key int
LocationId
CreatedDate Datetime

Table3

Primary_key int
Forign_key int
UserId
OrganisationId
CreatedDate Datetime

How can I Select latest created 10 records from all of the 3 tables.
Note that the 3 tables have different structure

sql server 2005

  • 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-23T07:15:27+00:00Added an answer on May 23, 2026 at 7:15 am

    If you want “last 10 per table”

    SELECT
        *
    FROM
        (
        SELECT
            Primary_key, Forign_key,
            UserId, OrganisationId, NULL AS LocationId, NULL AS PostID,
            CreatedDate, 'table3' AS Source,
            ROW_NUMBER() OVER (ORDER BY CreatedDate DESC) AS rn
        FROM table3
        UNION ALL
        SELECT
            Primary_key, Forign_key,
            NULL, NULL, LocationId, NULL,
            CreatedDate, 'table2',
            ROW_NUMBER() OVER (ORDER BY CreatedDate DESC) AS rn
        FROM table2
        UNION ALL
        SELECT
            Primary_key, Forign_key,
            NULL, NULL, NULL, PostID,
            CreatedDate, 'table1',
            ROW_NUMBER() OVER (ORDER BY CreatedDate DESC) AS rn
        FROM table
        ) T
    WHERE
       t.rn <= 10
    

    For “last 10 over all tables”

    SELECT TOP 10
        *
    FROM
        (
        SELECT
            Primary_key, Forign_key,
            UserId, OrganisationId, NULL AS LocationId, NULL AS PostID,
            CreatedDate, 'table3' AS Source
        FROM table3
        UNION ALL
        SELECT
            Primary_key, Forign_key,
            NULL, NULL, LocationId, NULL,
            CreatedDate, 'table2'
        FROM table2
        UNION ALL
        SELECT
            Primary_key, Forign_key,
            NULL, NULL, NULL, PostID,
            CreatedDate, 'table1'
        FROM table
        ) T
    ORDER BY
        CreatedDate DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables CREATE TABLE table1 (id int primary key auto_increment,....); CREATE TABLE
I have the following two tables: CREATE TABLE `table1` ( `ID` int(11) NOT NULL
I have a scenario like this: There are two tables table1 and table2 .
In a table I have the following schema table1: playerID int primary key, nationalities
I have two database tables with the following structure: actions: action_id int(11) primary key
I have 2 tables: create table numbers2 ( id1 int IDENTITY(1,1) not null, id2
I have the following tables: CREATE TABLE IF NOT EXISTS `Person_Categories` ( `PrsCatID` int(11)
I have tables foo and bar: create table foo(a int, b varchar(10), primary key
I'm using EF v1. I have following tables: CREATE TABLE category ( category_id int
I have two tables: gallery and pictures: gallery id int (auto increment, primary key)

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.