MySQL error #1064 near UNION version: 5.5.27

What’s the problem?

SELECT post_title
FROM wp_posts
WHERE post_type='tutorial' AND post_status='publish' 
LIMIT 3;
UNION
SELECT post_title FROM wp_posts
WHERE post_type='news' AND post_status='publish'
LIMIT 2;

It’s showing error in mysql query box and definitely not working in wordpress environment.

Related posts

Leave a Reply

1 comment

  1. The code you’ve posted is 2 queries. It is not legal to start a SQL statement with Union. I suspect that you intend this to be a single query – try removing the semi-colon before ‘UNION’. Without testing I don’t know if it will allow LIMIT in the context of a UNIONd query either (but really, using LMIIT without an ORDER BY is just plain silly). If not then you’d have to implement the 2 select’s as subselects then union the results.