What is the proper syntax to combine these two queries?
SELECT clicks FROM clicksTable WHERE clicks > 199 ORDER BY clicks ASC LIMIT 1
and
SELECT clicks FROM clicksTable ORDER BY clicks DESC LIMIT 1
I tried:
SELECT clicks FROM clicksTable WHERE clicks > 199 ORDER BY clicks ASC LIMIT 1
UNION
SELECT clicks FROM clicksTable ORDER BY clicks DESC LIMIT 1;
but I get “Incorrect usage of UNION and ORDER BY”.
EDIT
Additionally, I want the result to be returned in a single row. So that I can access the value in php eg
$row['nextclick'] and $row['topclick']
From Simon’s suggestion, I should not use UNION because I want to return a single row of data
You can’t
ORDER BYin your firstSELECTand thenUNIONit.Edit
You can however
as in the MySQL UNION documentation
Which then makes your SQL
Edit 2
To return in an
array