Reputation: 251062
The following query works in MySql 5.0
SELECT SQL_NO_CACHE
ItemId,
AnotherColumn
FROM
TableOne
UNION
SELECT SQL_NO_CACHE
ItemId,
AnotherColumn
FROM
TableTwo
But in MySql 5.5 I get the following error:
MySql.Data.MySqlClient.MySqlException: Incorrect usage/placement of 'SQL_NO_CACHE'
What is the correct placement of SQL_NO_CACHE for UNION queries?
If I put SQL_NO_CACHE on one side of the UNION, will it affect both sides?
Upvotes: 4
Views: 3630
Reputation: 251062
As of MySql 5.5.3, you just need to specify SQL_NO_CACHE in the first SELECT of a UNION query:
SELECT SQL_NO_CACHE
ItemId,
AnotherColumn
FROM
TableOne
UNION
SELECT
ItemId,
AnotherColumn
FROM
TableTwo
It applies to the whole query. If you try and specify it in the subsequent SELECT statements it will error (and it is also now allowed in sub-queries).
Upvotes: 6