Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Convert a SELECT column to Date in MySql

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading