gosi123 gosi123 - 1 month ago 11
MySQL Question

Select left 4 characters

I have a database table name

monthly
. In that table, I have a column name
month
. In that month, I have few database values 201601, 201602, 201501 and 201502.

How do I write a sql query to select only those that starts with 2015?

From what I researched and tried, I am supposed to use a syntax called
LEFT
?

This is what I tried:

SELECT month, LEFT(month, 4) FROM monthly;


What I know is that I am missing a
where
statement to tell that I want only
2015
.

So how do I write this statement?

Answer

Assuming you want to get the entire column:

SELECT * FROM monthly WHERE month LIKE '2015%'
Comments