Aamit Aamit - 1 month ago 4x
SQL Question

Getting different resultset based on data type

I have a table tbl_item in which item_id is varchar. when i use the queries below 1 get different results.

  1. select * from tbl_item where item_id between 1 and 100 order by item_id

  2. select * from tbl_item where item_id between '1' and '100' order by item_id

Since item_id data type is varchar so query 2 seems the right one but produces wrong result. It only lists items with item_id 1

Why is there this descrepancy in the results?


Thanks guys for helping. I found the correct way to get this done. The query below was initially giving some issues, don't know why but now it works.

select * from tbl_item where item_id>='1' and item_id<='100' order by item_id