kpmDev
kpmDev

Reputation: 1370

Mysql BETWEEN Statement for String

I am storing data in varchar (date + additional information). I want to filter data in between range.

For Example:

I have datesubact column like below.

2013/07/01,S
2013/07/26,A
2013/07/05,S
2013/07/06,S
.
.

I want to filter the range between 2013/07/01 to 2013/07/06. How do I put Mysql query for this?... Please anyone help me...

Upvotes: 2

Views: 582

Answers (3)

Biju Soman
Biju Soman

Reputation: 438

This should work

SELECT  * from Tbl WHERE  date('2013/07/01,S')  BETWEEN @startDate and @EndDate  ;

see this SQLFiddle

Upvotes: 0

ClaireG
ClaireG

Reputation: 1244

Divide the dates and additional information and put them in separate columns. After that you can query like the following:

SELECT _yourColumnName FROM tbl_yourTableName
WHERE _date
BETWEEN '2013/07/01' AND '2013/07/06'

Do not ever leave multiple values in a single column. It will only cause problems for you and for those who will have their work based on your own.

Upvotes: 0

juergen d
juergen d

Reputation: 204756

Never, never, never store multiple values in one column!

Like you see now this will only give you headaches. Normalize your table.

It should be

date_column (type = date) | other_column (type = char(1))
--------------------------+------------------------------
2013/07/01                |    S
2013/07/26                |    A
2013/07/05                |    S
2013/07/06                |    S

Upvotes: 4

Related Questions