N
N
Name2018-01-27 19:38:37
SQL
Name, 2018-01-27 19:38:37

How to output from two tables in turn?

There are two tables:
tab1 (id, title, ...)
tab2 (id, title, ...)
tab3 (id, ...)
you need to display the title together from two tables in turn, first table 2, then 1
like this the request deduces only from the first table.
How correctly to add that the second table was connected?

$sql = $db->super_query("SELECT tb1.id, title, tb3.id FROM `tab1` tb1, `tab3` tb3 WHERE tb1.id = tb3.id ORDER by `id`");
foreach($sql){ ...}

in the query, it should be the same (WHERE tb2.id = tb3.id)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2018-01-27
@tsklab

Use UNION.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question