-1

I am attempting to run a query on my database where I retrieve all results from the Employees table if there is a matching result in First_Name, Last_Name, or Title. For some reason the only category that returns a result is Title. If I type a name that I know is in the first name or last name I get no results. I'm new to SQL so any help would be appreciated.

Query: SELECT * FROM Employees WHERE First_Name OR Last_Name OR Title LIKE "Hollis"

Tables

Current Results

Griffin M
  • 13
  • 1
  • 1
    The `OR` operator does not do what you think it does. [Please familiarize yourself with the concepts of disjunctive vs conjunctive operators](https://en.wikipedia.org/wiki/Logical_disjunction). – Dai Jul 14 '21 at 16:53

1 Answers1

1

This:

WHERE First_Name OR Last_Name OR Title LIKE "Hollis"

Is not doing what you expect. It is treating First_Name and Last_Name as boolean conditions. That means that it is converting them to numbers and checking if the number is or is not 0. In fact, with no leading digits, the names are probably always 0, so they evaluate to "false".

What you seem to intend is:

WHERE 'Hollis' IN (First_Name, Last_Name, Title)
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786