0
select * from table where column * 'value';

I accidentally wrote * for my where statement instead of =, and the query returned all rows in the table.

Made me wonder why an error wasn't thrown instead.

What does the * operator do in a where statement?

New contributor
user172301 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
2

The SQL

WHERE column * value

is a numeric operation of multiplication, and when the value of the expression (column * value) isn't 0, that is equivalent to TRUE so will return the row.

  • 2
    Maybe you should remark this syntax is only valid for MySQL and SQLLite. – McNets Feb 12 at 10:39
  • Starting with V11 this is also valid in Db2 (as long as the multiplication is valid) – Lennart Feb 12 at 11:29
  • In MySQL, if column and/or 'value' are strings, you get a Warning " Truncated incorrect DOUBLE value:..." for each string. – Rick James Feb 12 at 19:40
2
SELECT * FROM <MY_TABLE> WHERE <COL_NAME> * 1;

Although this syntax works for MySQL 8.0 and SQLite 3.8 you will get an error on mostly all other RDBMS.

SQL Server 2017

An expression of non-boolean type specified in a context where a condition is expected, near ';'.

PostgreSQL 11

For integer columns:

ERROR: argument of WHERE must be type boolean, not type integer

For text/varchar columns

ERROR: operator does not exist: character varying * integer

Oracle 18c

ORA-00920: invalid relational operator

Your Answer

user172301 is a new contributor. Be nice, and check out our Code of Conduct.

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.