1

I have a single table where I am attempting to access rows via a simple SQL query I think, however, I am misunderstanding the way the OR modifier technically works. The statement I am trying to query is as follows:

SELECT * from table WHERE name OR vehicle OR state OR address LIKE '%input term here%';

This either returns an empty table, or in some instances the entire table. If I pare down the statement to include 0 OR modifiers it works, the trouble begins when I attempt to chain them like above. I'm looking for the simplest way to have one single query for the table, I think this might not be possible the way I'm going about it though. Any ideas?

NOTE: I am sanitizing input, I changed the end of the query for readability.

1
  • 2
    You need to add LIKE '%input term here%' for every column you want to apply it to. Commented Jan 6, 2017 at 9:45

2 Answers 2

4

You need to repeat the LIKE expression for each column, i.e.

SELECT *
FROM yourTable
WHERE name    LIKE '%input term here%' OR
      vehicle LIKE '%input term here%' OR
      state   LIKE '%input term here%' OR
      address LIKE '%input term here%'
Sign up to request clarification or add additional context in comments.

Comments

3
SELECT * from table 
WHERE name LIKE '%input term here%' 
OR vehicle LIKE '%input term here%' 
OR state LIKE '%input term here%' 
OR address LIKE '%input term here%';

try this out

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.