Was writing a sql statment and the CTE query works but when wrapped it is giving me a syntax 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 'dateCTE (id, firstDate) AS ( select id, min(date' at line 1
With dateCTE (id, firstDate) AS (
select id, min(date)
from notes
where deletion_time is null
and signed_time is not null
group by 1)
select *
from dateCTE;
Shoot sorry the where clause was part of it, I just missed it while copying it to stackoverflow.
3 Answers 3
We are running 5.7 not 8 and this is just not supported.
Comments
Not sure why you need cte, only single select statement would help you :
select id, min(date)
from notes
where deletion_time is null and signed_time is not null
group by id;
Note : You need where clause to filter the nulls & calls to `cte immediate after declaration :
With dateCTE (id, firstDate) AS (
select id, min(date)
from notes
where deletion_time is null and signed_time is not null
group by id
)
select *
from dataCTE;
1 Comment
select * from dateCTE;Two things. You are missing a where in the CTE. And you are missing a select. So:
With dateCTE (id, firstDate) AS (
select id, min(date)
from notes
where deletion_time is null and signed_time is not null
group by 1
)
select *
from dataCTE;
Note: This assumes that your database supports group by 1.
1 Comment
Explore related questions
See similar questions with these tags.
dateCTE?dateCTE? Shouldn't there be anything to be selected from that?select * from dateCTE;I got the syntax errorfrom dateCTE