0

I have this query:

SELECT DISTINCT CONCAT (MONTH(`Date`),'-',YEAR(`Date`)) 
from wp_result_plugin 
WHERE Bet=2 
AND month(`Date`) = EXTRACT(month FROM (NOW())) 
ORDER BY MONTH(`Date`) ASC

UNION 

SELECT DISTINCT CONCAT (MONTH(`Date`),'-',YEAR(`Date`)) 
from wp_result_plugin 
WHERE Bet=2 
AND month(`Date`) 
ORDER BY MONTH(`Date`) ASC

I am seeing this error:

Incorrect usage of UNION and ORDER BY

How to make this work?

3

Wrap the selects into parentheses

(SELECT DISTINCT CONCAT (MONTH(`Date`),'-',YEAR(`Date`)) from wp_result_plugin WHERE Bet=2 AND month(`Date`) = EXTRACT(month FROM (NOW())) ORDER BY MONTH(`Date`) ASC )
UNION 
(SELECT DISTINCT CONCAT (MONTH(`Date`),'-',YEAR(`Date`)) from wp_result_plugin WHERE Bet=2 AND month(`Date`) ORDER BY MONTH(`Date`) ASC)
  • @zugguy thank you man this jot me what i needed just one more thing can i make this in to a single query – zeeshan Apr 18 '15 at 20:38
  • Well to tell you the truth, I didn't actually study your queries before and now that I did, they are strange; month(Date) is always != 0 so this part: AND month(Date) in second query is superfluous; also, you likely have more than one row with same values for month(Date) so your order by clauses will not produce deterministic results... perhaps you could give the structure of wp_result_plugin table and explain what you're trying to do and I might have a suggestion? – zgguy Apr 19 '15 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.