Reputation: 11
everybody
I want to retrieve the records from a table(price) based on the following query.My table is
+-----------+
| pprice |
+-----------+
| 10 lakhs |
| 11 lakhs |
| 12 crores |
| 13 lakhs |
| 15 crores |
| 16 lakhs |
+-----------+
I'm using the following query
select * from price where pprice between '10 lakhs' and '20 lakhs';
but it returns the following result
+-----------+
| pprice |
+-----------+
| 10 lakhs |
| 11 lakhs |
| 12 crores |
| 13 lakhs |
| 15 crores |
| 16 lakhs |
+-----------+
what's the problem in my query.please give me reply for this.
Upvotes: 1
Views: 520
Reputation: 107706
If you're dealing with equal magnitudes, such as lakhs in your example, you can do something like this:
select *
from price
where pprice between '10 lakhs' and '20 lakhs'
and pprice like '__ lakhs';
Upvotes: 1
Reputation: 11096
What happens is, that your mySql is not aware about lakhs and crores and splits off the number part at the first space while auto-converting the formats. And then: The result is quite proper!
Besides the design pattern here (measure as part of the data field, normalization, ...) what is the relation between lakhs and crores ? How should mysql know that 1 crore is larger than 1 lakhs (ore vice cersa, I don't what this is).
Upvotes: 0