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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:28:06+00:00 2026-05-30T15:28:06+00:00

I have 4 table, default_table, table_a, table_b, table_c, each have two columns, I want

  • 0

I have 4 table, default_table, table_a, table_b, table_c, each have two columns,
I want to select name and id from all table then sort it,
I try"SELECT Name,ID FROM default_table, table_a, table_b, table_c ORDER BY Name"
but this give me error, so can someone help me with this problem, i need code in sql or php, or even javascript if it can

  • 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-30T15:28:08+00:00Added an answer on May 30, 2026 at 3:28 pm

    Since order by is applied after unioning, you can just do:

    select id, name from default_table
        union all select id, name from table_a
        union all select id, name from table_b
        union all select id, name from table_c
    order by name
    

    Your problem is that you’re doing a Cartesian product of all the table data so it’s can’t figure out which id or name you mean. Even if it could, you’d get way more rows than you’d expect, due to the multiplicative effect. You want to join the data simply by adding all the rows to the output.


    Explaining the distinction further, let’s say you have two tables:

    table1          table2
    ======          ======
    id     name     id     name
    --     ----     --     ------
     1     pax       1     jill
     2     bob       2     debbie
     3     joe
    

    The query:

    select a.id, a.name, b.id, b.name from table1 a, table2 b
    

    (the cartesian product) will give you:

    1 pax 1 jill
    1 pax 2 debbie
    2 bob 1 jill
    2 bob 2 debbie
    3 joe 1 jill
    3 joe 2 debbie
    

    (the row count is the product of the individual row counts) whereas:

    select id, name from table1
    union all
    select id, name from table2
    

    (the union) will give you:

    1 pax
    2 bob
    3 joe
    1 jill
    2 debbie
    

    (the row count is the sum of the individual row counts).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want make query select all names from table 'a' where from table 'b'
I have two product tables. Table A is the default table (comes from data
I have two table cpuinfo and jobinfo. I want to create report using both
by default I have one column in MySQL table to be NULL. I want
I have table with 50 entries (users with such details like Name Surname Location
I have table rows of data in html being filled from a CGI application.
I have a table structure like the following: table a: id int name varchar
I have two MySql tables as shown below with the data shown: CREATE TABLE
I have a MySQL table with many numeric columns (some INT, some FLOAT). I
I have a query that takes 2minutes to count from table A and update

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.