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:
- John Doe (Insured)
InsuredID = 1 - Joanna Doe (Accompany)
InsuredID = 1 - Johnny Doe (Accompany)
InsuredID = 1 - Bill Gates (Insured)
InsuredID = 2 - Steve Jobs (Insured)
InsuredID = 3 - Steve Balmer (Accompany)
InsuredID = 3
Something like this should work:
Basically insert a fake column to identify what table the lines are coming from, then sort by
insuredid, then by our arbitrary table number.