1

Ok so a bit of a funny question here. I have two tables: -

  • LiveTable
  • ArchiveTable

The data is as follows: -

Table: LiveTable            Table: ArchiveTable

| ID | NAME      |          | ID | NAME      |
------------------          ------------------
|  1 | Test One  |          |  4 | Test Four |
------------------          ------------------
|  2 | Test Two  |          |  5 | Test Five |
------------------          ------------------
|  3 | Test Three|          |  6 | Test Six  |

What I want to do is merge them into one table for querying purposes only. Not as a Database Structure.

In essence when I do a PHP Loop I want the results to work like this: -

Merged Results

| ID | NAME      |
------------------
|  1 | Test One  |
------------------
|  2 | Test Two  |
------------------
|  3 | Test Three|
------------------
|  4 | Test Four |
------------------
|  5 | Test Five |
------------------
|  6 | Test Six  |

How would I go about doing this? Also is there a way of doing this with Doctrine?

2
  • print ist array than second array or use array_merge() Commented Oct 19, 2016 at 11:24
  • 1
    Create view Using those two tables; Commented Oct 19, 2016 at 11:25

4 Answers 4

1

You can use an SQL query with UNION:

SELECT ID, Name
FROM LiveTable            

UNION ALL

SELECT ID, Name
FROM ArchiveTable

Note: UNION ALL will retain duplicates. If you want to remove duplicate records, then use UNION.

Sign up to request clarification or add additional context in comments.

Comments

1

Yould use UNION:

SELECT id, name FROM tbl1
UNION ALL
SELECT id, name FROM tbl2

Comments

1

Create DB view using above two tables

CREATE VIEW view_name AS SELECT 
  id, name FROM tbl1
UNION
  id, name FROM tbl2 

Then you can query on your view

Comments

0

you can use the sql query multi table select

Select * from LiveTable,ArchiveTable

that's it

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.