I have 3 different queries that basically sort the same results by different parameters and I would like MySQL to return their results merged into 3 different columns:
SELECT `text` AS `popular` FROM `searches` WHERE `text` LIKE 'Tyr%' ORDER BY `hits` DESC LIMIT 10
SELECT `text` AS `recent` FROM `searches` WHERE `text` LIKE 'Tyr%' ORDER BY `datetime` DESC LIMIT 10
SELECT `text` AS `matches` FROM `searches` WHERE `text` LIKE 'Tyr%' ORDER BY `matches` DESC LIMIT 10
First query returns this:
| popular |
| A |
| B |
| C |
Second query returns this:
| recent |
| B |
| C |
| A |
Third query returns this:
| matches |
| C |
| A |
| B |
I would like to merge those results so that I get this with a single query:
| popular | recent | matches |
| A | B | C |
| B | C | A |
| C | A | B |
This is what I tried so far, but the result I get is totally messed up.
SELECT * FROM
(SELECT `text` AS `popular` FROM `searches` WHERE `text` LIKE 'Tyr%' ORDER BY `hits` DESC LIMIT 10) AS A
JOIN (SELECT `text` AS `recent` FROM `searches` WHERE `text` LIKE 'Tyr%' ORDER BY `datetime` DESC LIMIT 10) AS B ON 1=1
JOIN (SELECT `text` AS `matches` FROM `searches` WHERE `text` LIKE 'Tyr%' ORDER BY `matches` DESC LIMIT 10) AS C ON 1=1