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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:38:48+00:00 2026-06-13T14:38:48+00:00

I need to merge two data schema into one. I have Schema1 and Schema2.

  • 0

I need to merge two data schema into one. I have Schema1 and Schema2. I need to join these two into Schema3. Furthermore, I have a Select statement which queries a data set but I can’t figure out how to use the select statement on the data set containing both tables (both Schema1 and Schema2) and combine them into the new table schema3 which is a table in the same data set comprised of both table’s fields.

Example

Schema 1
ID,
Food,
Book,
Rice,
Cave

Schema 2
ID ,
Carpet,
Strings,
Run

Schema 3
ID,
Food,
Book,
Rice,
Cave,
Carpet,
Strings,
Run

Fill the Schema3 Table with this command

Sql Command:

Select * Schema1 [except ID] and all fields from Schema2 [exceptID] Inner Join 
Schema2 ON Schema1.ID = Schema2.ID
Where ID = {dynamically defined variable 'X'}

Please excuse the lack of proper syntax. The main issue here again is querying a dataset with the select statement and filling up a table with the results. Im not exactly connecting to my DB because I already filled a dataset locally.

——Edit ——
I really just need a way to create an array of data rows from a query of two tables.

  • 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-13T14:38:49+00:00Added an answer on June 13, 2026 at 2:38 pm

    You could use this extension method here which i’ve written from scratch recently for another question. It enables to merge multiple tables by a common key. If no key is specified it will just use the default DataTable.Merge method:

    public static DataTable MergeAll(this IList<DataTable> tables, String primaryKeyColumn)
    {
        if (!tables.Any())
            throw new ArgumentException("Tables must not be empty", "tables");
        if(primaryKeyColumn != null)
            foreach(DataTable t in tables)
                if(!t.Columns.Contains(primaryKeyColumn))
                    throw new ArgumentException("All tables must have the specified primarykey column " + primaryKeyColumn, "primaryKeyColumn");
    
        if(tables.Count == 1)
            return tables[0];
    
        DataTable table = new DataTable("TblUnion");
        table.BeginLoadData(); // Turns off notifications, index maintenance, and constraints while loading data
        foreach (DataTable t in tables)
        {
            table.Merge(t); // same as table.Merge(t, false, MissingSchemaAction.Add);
        }
        table.EndLoadData();
    
        if (primaryKeyColumn != null)
        {
            // since we might have no real primary keys defined, the rows now might have repeating fields
            // so now we're going to "join" these rows ...
            var pkGroups = table.AsEnumerable()
                .GroupBy(r => r[primaryKeyColumn]);
            var dupGroups = pkGroups.Where(g => g.Count() > 1);
            foreach (var grpDup in dupGroups)
            { 
                // use first row and modify it
                DataRow firstRow = grpDup.First();
                foreach (DataColumn c in table.Columns)
                {
                    if (firstRow.IsNull(c))
                    {
                        DataRow firstNotNullRow = grpDup.Skip(1).FirstOrDefault(r => !r.IsNull(c));
                        if (firstNotNullRow != null)
                            firstRow[c] = firstNotNullRow[c];
                    }
                }
                // remove all but first row
                var rowsToRemove = grpDup.Skip(1);
                foreach(DataRow rowToRemove in rowsToRemove)
                    table.Rows.Remove(rowToRemove);
            }
        }
    
        return table;
    }
    

    You can call it in this way:

    var tables= new[] { Schema1, Schema2};
    DataTable Schema3 = tables.MergeAll("ID");
    

    Edit: If you don’t need a new DataTable with the merged schema you could also use Linq-To-DataSet (now VB.NET):

    Dim schema3 = From r1 In schema1
              Join r2 In schema2 On r1.Field(Of Int32)("ID") Equals r2.Field(Of Int32)("ID")
              Select New With {
                    .ID = r1.Field(Of Int32)("ID"),
                    .Food = r1.Field(Of String)("Food"),
                    .Book = r1.Field(Of String)("Book"),
                    .Rice = r1.Field(Of String)("Rice"),
                    .Cave = r1.Field(Of String)("Cave"),
                    .Carpet = r2.Field(Of String)("Carpet"),
                    .Strings = r2.Field(Of String)("Strings"),
                    .Run = r2.Field(Of String)("Run")
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple tables that need to be merged into one. SELECT name, SUM(money)
I need to merge two SELECT statements. There are two tables in my database,
I have two files, one with webservice description (wsdl), second with data structures used
I have two tab delimited csv files (with headers) that I need to merge
I need to find a way to join two XML files when they have
DESCRIPTION I have two datasets with information that I need to merge. The only
listview want to merge two different arraylist into one adapter. i try using the
I have two dataframes df1 = data.frame(Sites=c(A,B,C),total=c(12,6,35)) df2 = data.frame(Site.1=c(A,A,B),Site.2=c(B,C,C), Score=c(60,70,80)) I need to
I am trying to merge data between two identical schema databases using Linq-to-sql: List<Contact>
I need to compare numeric data from two datatables with the same schema. For

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.