Reputation: 19164
I have this SQL query is MySql, not working:
select email, cast(select tag from user_tags where userid=users.id limit 1,date) as date
from users
The error is: "select" is not valid at this position for this server version, and it highlights the select right after cast.
Upvotes: 1
Views: 690
Reputation: 22811
You can cast an expression not a statement.
select email, cast((select tag from user_tags where userid=users.id limit 1) as date) as date
from users
Upvotes: 1
Reputation: 65288
You can cast a column but not a whole query. So consider using
SELECT email,
(SELECT CAST(tag AS DATE) FROM user_tags WHERE userid=u.id LIMIT 1) AS date
FROM users AS u
as a correlated subquery containing a column with type conversion
Upvotes: 1