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

  • Home
  • SEARCH
  • 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 8524479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:41:52+00:00 2026-06-11T07:41:52+00:00

I have 2 tables. 1 table have 3 rows and another table have 5

  • 0

I have 2 tables. 1 table have 3 rows and another table have 5 rows. I wanted to join this both tables together and the result should show 3rows and 5 rows respectively. Is there any ways that could achieve that using sql statement? Any help will be appreciated.

  • 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-11T07:41:54+00:00Added an answer on June 11, 2026 at 7:41 am

    You can use UNION for this,

    SELECT colA, colB, colC, 1 as OrderThis
    FROM tableA
    UNION ALL
    SELECT colA, colB, colC, 2 as OrderThis
    FROM tableB
    ORDER BY OrderThis ASC
    

    There are two basic rules of using UNION

    • the number of columns must be the same from both queries
    • the data types must be compatible

    UNION has an optional parameter ALL. if you omit ALL parameter, UNION will distinctly display all unique records that were combined.

    As you can see, I have added a virtual column OrderThis. This will be the basis for the ordering of your rows. But the Problem is it will show on your result list. the solution is by wrapping it in a subquery,

    SELECT colA, colB, colC
    FROM
    (
        SELECT colA, colB, colC, 1 as OrderThis
        FROM tableA
        UNION ALL
        SELECT colA, colB, colC, 2 as OrderThis
        FROM tableB
    ) a
    ORDER BY OrderThis ASC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a join which deletes rows that match another table but the joining
I have two identical tables and need to copy rows from table to another.
I have three tables of data: table: cars [10,000 rows] table: planes [2,000 rows]
i have 5 tables,in every table it has 4 rows. so i need to
I have a table like this, all rows have the structure like 1st data
I want to copy some rows data to another table, For example: I have
I have two tables and I'm looking for the rows in one table where
I have 2 tables. Table_1 has product 3 rows : ID, Quantity and Price.
I have a table (table variable in-fact) that holds several thousand (50k approx) rows
how remove html table rows after 2nd row? if in table have 5 row,

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.