0

I have a column in a table with data type of tiny int. Its having values like 1 and 0. I tried a select query as

SELECT * from table_name where filed_name = 'Y'; 

This results me all records which is having zero in it. I didn't understand how query execution happens. Please help me to understand this

stackMonk
  • 1,033
  • 17
  • 33
Arumugam
  • 1
  • 2
  • http://stackoverflow.com/questions/10852337/true-false-vs-0-1-in-mysql true and false are synonyms for 1 and 0 refer to that previous question – Paul Maxwell Sep 10 '14 at 07:27
  • I need to understand from my question is that how an integer field comparing with a character returns true(1). If you try above query as 'Select field_name = 'Y' from table_name' will return 1 as result. – Arumugam Sep 10 '14 at 07:34

2 Answers2

0

TINYINT does not store strings values like 'Y' or 'N', it stores integers 0 or 1. If you want all datarows with value 'Y' you have to filter by 1 (integer) example:

SELECT * FROM myTable WHERE myTinyColumn = 1
Edi G.
  • 2,432
  • 7
  • 24
  • 33
0

When the string is converted to a number, it becomes the value 0. Thats why your are getting all records with value 0

SELECT * from table_name where filed_name = 'Y';

here 'Y' automatically converted to 0

Use instead

SELECT * from table_name where filed_name = 1;
vikrant singh
  • 2,091
  • 1
  • 12
  • 16