subtract - MySQL - subtracting one query set from another -
i'm not sure how lecture notes tell me use "except" in sql mysql not seem support this. i've been thinking should use "where not in" alternative, problem both of these columns need compare have different names.
here incorrect query:
(select id projects) id not in (select project_id projects_viewed);
i want select rows table "projects" id column not appear in "projects_viewed" table. column called "project_id" instead of "id" because it's foreign key.
basically logic behind result set returned query should project id's have not been viewed (the ones in 2nd table).
there several ways this. here's 1 using outer join
null
check:
select p.id projects p left join projects_viewed pv on p.id = pv.project_id pv.project_id null
and not in
:
select id projects id not in (select project_id projects_viewed)
i think these methods more efficient in mysql
not exists
.
Comments
Post a Comment