How to display two different database tables in php

Asked

Viewed 1,524 times

0

Hello personal is the following, I have 2 separate tables, and can not do Inner Join, because they have no data in common, I wonder if it is possible to display these two tables in a single page.

  • 2

    yes, with two separate queries and display one below the other... (I have a virtual store that reaches 155 queries to DB in a single page, and all in 0,385ms)

2 answers

1

You can use the CROSS JOIN:

SELECT *
FROM tabela1
CROSS JOIN tabela2

0

Hello, another idea is to use UNION, but the tables should have the same structure and the same number of columns, example:

SELECT *
FROM   table1
UNION ALL
SELECT *
FROM   table2

or

SELECT t1.id, t1.nome
FROM   table1 t1
UNION ALL
SELECT t2.id, t2.nome
FROM   table2 t2

Browser other questions tagged

You are not signed in. Login or sign up in order to post.