wowpatrick
wowpatrick

Reputation: 5180

Using SQL Where clause with OR operator

Is this possible with normal, non-vendor specific SQL? If not, what can one do to search two different columns?

SELECT COUNT(*) 
FROM airpapr_base
WHERE article_content_title_en
LIKE '%google%'
OR
WHERE article_content_text_en
LIKE '%google%'

Upvotes: 0

Views: 880

Answers (3)

Dave Costa
Dave Costa

Reputation: 48111

OR is simply a logical operator for combination of predicates. It can be used in the same manner as AND:

SELECT COUNT(*) 
FROM airpapr_base
WHERE article_content_title_en LIKE '%google%'
OR article_content_text_en LIKE '%google%'

If you combine AND and OR, then of course you have to be aware of operator precedence to be sure conditions are combined in the order you are expecting (or simply parenthesize everything to be certain).

Upvotes: 1

Dyppl
Dyppl

Reputation: 12381

SELECT COUNT(*) 
FROM airpapr_base
WHERE article_content_title_en
LIKE '%google%'
OR
article_content_text_en
LIKE '%google%'

Notice the lack of second WHERE. It should work

Relevant tutorials: WHERE clause (section "SQL - Where with Multiple Conditionals"), Search conditions (MSDN)

Upvotes: 3

Jon Egerton
Jon Egerton

Reputation: 41539

Have a go with:

SELECT COUNT(*) 
FROM airpapr_base
WHERE 
    article_content_title_en LIKE '%google%'
    OR article_content_text_en LIKE '%google%'

Upvotes: 0

Related Questions