Is it possible to check multiple attributes without using AND or OR in mysql? If not what is the logic behind denying such action?

mahfuj asif :

Please consider the following table

|id| first_name| last_name| nick_name|

What is the best way to find names that matches certain value? Following query is working but is there any better way?

select * from names where first_name = val OR last_name = val OR nick_name = val

Can i do something like -

select * from names where first_name OR last_name OR nick_name = val

If not then why mysql does not allow to perform check on multiple attributes in a single condition?

Prabhjot Singh Kainth :

You can use IN function of MySQL.

MySQL IN() function finds a match in the given arguments.

select * from names where val IN(first_name,last_name,nick_name);

This won`t work :

select * from names where first_name OR last_name OR nick_name = val

As this will always result in false condition.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=14023&siteId=1