1

I have table with varchar column. Some rows are empty, some have content. While preparing SELECT statement, I accidentaly run query like that:

SELECT column_x FROM table_x WHERE column_x;

It gave me all rows where column_x content begins with numbers. How WHERE condition works in this case and why it selects that values but not values which begins with letters or special signs?

  • 2
    column_x can be, or interpreted as a boolean. – Colin 't Hart Apr 1 '15 at 10:27
  • 2
    What Colin said above. column_x values are converted to integers and then 0 is interpreted as FALSE and any other number as TRUE. – ypercubeᵀᴹ Apr 1 '15 at 10:41
  • If you run SELECT column_x, CAST(column_x AS UNSIGNED) FROM table_x ;, you can see the result of the cast. – ypercubeᵀᴹ Apr 1 '15 at 10:48
  • Exactly, value "11a" is converted to "11", and "a11" to "0", so it must be conversion to integer. Now I understand what's going on, thanks! – dmk.i-t Apr 1 '15 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.