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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:44:45+00:00 2026-05-27T23:44:45+00:00

I am new with joining tables. ClassList ======================== ID Level 1 2 2 2

  • 0

I am new with joining tables.

ClassList
========================
ID      Level
1       2
2       2
3       4
4       1
5       3
6       7

BoysList
========================
ID      Name        Age
1       Alex        13
2       Arnold      16
3       Barny       15

GirlsList
========================
ID      Name        Age
4       Arnie       12
5       Martha      17
6       Beth        15

I was able to join two tables. But, what if, in this situation, you have to combine first the two tables (BoysList and GirlsList) and then join it with ClassList.

The Resultset would be:

Result
================================================
ID      Name
4       Arnie           
6       Beth        
5       Martha      
1       Alex    
2       Arnold  
3       Barny       

order of the result would be list of boys girls first, name ASC. How do accomplish this?

  • 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-27T23:44:46+00:00Added an answer on May 27, 2026 at 11:44 pm

    the first thing you will do is to UNION the BoysList and GirlsList then INNER JOIN it with ClassList

    SELECT  iStudentList.`ID`,
        iStudentList.`Name`,
        iStudentList.`Age`,
        ClassList.`iOrder`
    FROM
    ClassList INNER JOIN 
        (SELECT `ID`, `Name`, `Age`, "A" as iOrder FROM BoyssList
            UNION
         SELECT `ID`, `Name`, `Age`, "B" as iOrder FROM GirlsList) as iStudentList
    ON ClassList.`ID` = iStudentList.`ID`
    ORDER BY ClassList.`iOrder` DESC, iStudentList.`Name` ASC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a new and am having some trouble with joining two tables. table1:
Working on joining up two legacy DB systems into new database where I can
I've got a query joining several tables and returning quite a few columns. An
Is this the proper way to accomplish joining 3 ( or more ) tables
I'm joining two tables - Contact and RetailTrainingUserLevelMap in a Select statement. (The common
ASP.NET 3.5 C# I am joining two tables using Linq. Table names are MapAssets
I have several tables that I am joining that I need to add another
I have a stored Procedure that works fine joining 2 tables together. I needed
I need to join a table on itself while joining other tables and doing
I'm joining a number of tables and want to create some tables or views

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.