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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:09:46+00:00 2026-06-18T08:09:46+00:00

I have two different tables. One is instructor and second is student . Both

  • 0

I have two different tables. One is instructor and second is student. Both table structure are as follows:

________INSTRUCTOR_________

instructorid schoolid instructorusername instructorfirstname instructorlastname instructortitle level
1             1        inst_A              first_A             Last_A              RN            3
2             1        inst_B              first_B             Last_B              TD            3
3             1        inst_C              first_C             Last_C              FP            3

________STUDENT_________

studentid   schoolid  studentusername    studentfirstname    studentlastname    level
1             1        stud_A              first_A             Last_A            4
2             1        stud_B              first_B             Last_B            4
3             1        stud_C              first_C             Last_C            4

Now, I want to select data from both tables where schoolid is ‘1’ and the result will be like Bellow :

________RESULT_________

id schoolid username firstname lastname title level
1   1        inst_A   first_A   Last_A   RN    3
2   1        inst_B   first_B   Last_B   TD    3
3   1        inst_C   first_C   Last_C   FP    3
1   1        stud_A   first_A   Last_A         4
2   1        stud_B   first_B   Last_B         4
3   1        stud_C   first_C   Last_C         4

Is there any way to do like this? Please can any one help me for this. I have never done like this before.

Thank you in Advance

  • 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-18T08:09:47+00:00Added an answer on June 18, 2026 at 8:09 am

    use UNION ALL (actually just UNION will do since students have no title). SInce table STUDENT doesn’t have title, you need to have an empty column with alias title so it will match the column count. If you don’t add extra column for title, you will have error message

    The used SELECT statements have a different number of columns...
    

    Full Query,

    SELECT  schoolid, 
            instructorusername username, 
            instructorfirstname firstName, 
            instructorlastname lastName,
            instructortitle title,
            level
    FROM    instructors
    UNION 
    SELECT  schoolid, 
            studentusername username, 
            studentfirstname firstName, 
            studentlastname lastName,
            '' title,
            level
    FROM    students
    
    • SQLFiddle Demo
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two different tables and i decided to merge them into one table...
I have an HTML document where I have two different tables. One is class
i have two tables one is called addons and holds information about different addons,
I have two tables, both named as say, Employee in two different schema HR
I have combined two different tables together, one side is named DynDom and the
I have two tables one called details and the other called c_details. Both tables
I have two tables in two different databases with same structure. I am exporting
How can I use two different tables for one entity in Symfony? I have
I have a table that has two foreign keys to two different tables with
I have two different tables to track location of equipment. The equipment table tracks

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.