kpratama
kpratama

Reputation: 133

Where clause doesn't work

I'm trying to get data from two tables. Here is my code:

select p.nim, p.title, s.name, p.year, substring(p.abstrak, 1, 100), p.path, p.status 
from student s 
join project p 
on s.nim = p.nim
where p.title like "%foot%" 
or p.title like "%ball%" and p.status = 'active'

The idea is not getting data with inactive status. But this query keeps returning data with inactive status.

what am I doing wrong here?

Upvotes: 0

Views: 146

Answers (1)

YogevSitton
YogevSitton

Reputation: 10108

Try this

select 
    p.nim, p.title, s.name, p.year, substring(p.abstrak, 1, 100), 
    p.path, p.status 
from student s 
join project p on s.nim = p.nim 
where 
    (p.title like "%foot%" or p.title like "%ball%") and p.status = 'active'

It's the same concept as Order of operations in math:

1 + 2 * 3 = 7

1 + (2 * 3) = 7

(1 + 2) * 3 = 9

Upvotes: 6

Related Questions