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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:58:33+00:00 2026-06-13T07:58:33+00:00

I have a database structure like this: • Insured table +———–+————–+—–+ | InsuredID |

  • 0

I have a database structure like this:

• Insured table

+-----------+--------------+-----+
| InsuredID |         Name | ... |
+-----------+--------------+-----+
|         1 |     John Doe | ... |
|         2 |   Bill Gates | ... |
|         3 |   Steve Jobs | ... |
+-----------+--------------+-----+

• Accompany table

+-------------+-----------+---------------+-----+
| AccompanyID | InsuredID |          Name | ... |
+-------------+-----------+---------------+-----+
|           1 |         1 |    Joanna Doe | ... |
|           2 |         1 |    Johnny Doe | ... |
|           3 |         3 | Steve Ballmer | ... |
+-------------+-----------+---------------+-----+

How can I have this result:

+----------------+-----+
|           Name | ... |
+----------------+-----+
|       John Doe | ... |
|     Joanna Doe | ... |
|     Johnny Doe | ... |
|     Bill Gates | ... |
|     Steve Jobs | ... |
|  Steve Ballmer | ... |
+----------------+-----+

How can I make the order of the query to be – Insured then Accompany‘s where the Accompany.InsuredID is equivalent to the Insured.InsuredID before the Accompany. It should be ordered like this:

  1. John Doe (Insured) InsuredID = 1
  2. Joanna Doe (Accompany) InsuredID = 1
  3. Johnny Doe (Accompany) InsuredID = 1
  4. Bill Gates (Insured) InsuredID = 2
  5. Steve Jobs (Insured) InsuredID = 3
  6. Steve Balmer (Accompany) InsuredID = 3
  • 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-13T07:58:35+00:00Added an answer on June 13, 2026 at 7:58 am

    Something like this should work:

    select name
    from (
     select insuredid, name, 0 ins
     from insured
     union all
     select insuredid, name, 1 ins
     from  accompany) isq
    order by insuredid, ins
    

    Basically insert a fake column to identify what table the lines are coming from, then sort by insuredid, then by our arbitrary table number.

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

Sidebar

Related Questions

I have a mysql database with a table structure like below : Table Name
I have a simple database structure like this: entries table +----+-----------+------------+-----------+------+ | id |
I have a sql table in my database accounts whose structure looks like this.
I have a table in a database with a structure like this Keywords id
I have a database structure like this - class Movie(db.Model): name = db.StringProperty() class
I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
I have this database structure, SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO; CREATE TABLE IF NOT EXISTS `announces` (
i have a database structure like this and am trying to print the rows
I have a database with trending data, the structure is like this: [Timestamp, System_State]
My database has a structure like this: 'Movimientos' table keeps records of all charges

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.