I'm tyring to use a where clause with a subquery inside a 'in'statement.
Thisis my query:
select *
from trading.historical_prices
where
date in (
(select date
from trading.historical_prices
group by date
order by date desc
limit 1)
union
(
select date
from trading.historical_prices
group by date
order by date desc
limit 7,1
)
)
limit 100
But I'm getting this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'union
(
select date
from trading.historical_prices
group by date
orde' at line 13
The union query works fine when it's ran alone. How can i fix this?
According to this answer , you don't parenthesis.
So your query would look like so :
SELECT *
FROM trading.historical_prices
WHERE date IN
(
SELECT date
FROM trading.historical_prices
GROUP BY date
ORDER BY date DESC limit 1
UNION
SELECT date
FROM trading.historical_prices
GROUP BY date
ORDER BY date DESC limit 7,
1) limit 100
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.