Home > Mobile >  SQL Syntax Problem: How do I get the first 4 letters and Uppercase
SQL Syntax Problem: How do I get the first 4 letters and Uppercase

Time:10-27

I am having a hard time getting the value in the database with a constraint of getting only the first 4 letters of the name as well as its in uppercase.

I am using MySQL on Command Prompt and so far I have tried this syntax and I always get this error,

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM STUDENTS' at line 1

The syntax I have tried;

SELECT UCASE(MID(NAME,1,3) FROM STUDENTS;

SELECT UPPER(SUBSTRING(NAME,1,3) FROM STUDENTS;

Tried all of them but I am still getting errors. Do you guys have any idea where I might be wrong?

CodePudding user response:

you have just missed a closing parenthesis.

SELECT UPPER(SUBSTRING(NAME,1,3)) FROM STUDENTS;

Also, to get the first 4 letters you should use SUBSTRING(NAME,1,4)

Cheers

CodePudding user response:

both of queries that you used have wrong parenthesis match (every opening parenthesis need closing one). If you want to get first 4 letters you should replace 3 with 4

SELECT UCASE(MID(NAME,1,4)) FROM STUDENTS;

SELECT UPPER(SUBSTRING(NAME,1,4)) FROM STUDENTS;
  • Related