-1

I am trying to get data from two table order by date:

(SELECT * FROM news ORDER BY date DESC LIMIT 3)
UNION
(SELECT * FROM article ORDER BY date DESC LIMIT 3);

This return 3 items from news order by date then 3 items from article order by date:

- news 1 (2018-8-22)
- news 2 (2018-7-19)
- news 3 (2018-6-13)
- article 1 (2018-8-22)
- article 2 (2018-7-18)
- article 3 (2018-6-12)

But I want to combine data order by date like this:

- news 1 (2018-8-22)
- article 1 (2018-8-22)
- news 2 (2018-7-19)
- article 2 (2018-7-18)
- news 3 (2018-6-13)
- article 3 (2018-6-12)

Any Idea?

Jens
  • 67,715
  • 15
  • 98
  • 113
Jack The Baker
  • 1,781
  • 1
  • 20
  • 51

1 Answers1

0

Add an outer select:

select * from
(SELECT * FROM news  LIMIT 3
UNION
SELECT * FROM article  LIMIT 3) as x
ORDER BY date DESC
Jens
  • 67,715
  • 15
  • 98
  • 113