P
P
pLavrenov2014-08-16 10:34:46
PHP
pLavrenov, 2014-08-16 10:34:46

Sorting by time data from 3 tables?

Tell me please. there are 3 tables with data. you need to display, for example, the last 20 (from 3 tables, not 20 from each) records sorted by time, which is indicated in one of the columns of these tables (it is called the same everywhere).
can this be solved with one complex query from the db? or how to do it at all.
php/mysql

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2014-08-16
@pLavrenov

dev.mysql.com/doc/refman/5.1/en/union.html

(SELECT a FROM t1 WHERE a=10 AND B=1 limit 20)
UNION
(SELECT a FROM t2 WHERE a=11 AND B=2 limit 20)
UNION
(SELECT a FROM t3 WHERE a=12 limit 20)
ORDER BY a LIMIT 20;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question