Samsquanch
Samsquanch

Reputation: 9146

Using NOT IN and OR not working as intended in MySQL

I'm attempting to write a query that will allow me to get any record from one table if the id doesn't exist in another table, or if it does exist and it also meets a second criteria. Below is what I attempted to do, but it always returns 0 rows:

SELECT p.pageid, p.pager FROM pages p, updates u
WHERE p.pageid NOT IN (SELECT pageid FROM updates)
   OR (p.pageid = u.pageid AND u.pagenums > 1000) LIMIT 100

From what I can tell this should work, but it's not. Any help is appreciated.

Upvotes: 0

Views: 60

Answers (1)

Adrian Serafin
Adrian Serafin

Reputation: 7715

Maybe try with this query

select p.pageid, p.pager from pages p where p.pageid not in (select pageid from updates)
union
select p.pageid,p.pager from pages p, updates u where p.pageid = u.pageid and u.pagenums > 1000

Upvotes: 1

Related Questions