php - Retrieving aggregated results from two queries -
i trying figure out best way compare results 2 queries , display difference.
- table 1 = user table
- table 2 = page table
- table 3 = assigned table
example: there users 1 , users 2 in user table. user 1 has been assigned 10 pages, user 2 has been assigned 1 page.
this works fine finding pages have assigned, 1 page example.
select * assigned_table user= 2
but can not figure out how results of other pages doesn't have access to.
this not work because there user 1 has access 10, gets results of other users except user2
select * assigned_table user != 2
so need pages user2 have access to, , pages not have access , display both results separately
any assistance appreciated.
sorry if similar topic posted elsewhere, unable find looking for.
you should use join
this. here's documentation on https://dev.mysql.com/doc/refman/5.0/en/join.html.
something like
select pt.pagename `assigned table` @ join `page table` pt on at.pageid = pt.id at.user = 2
this give listing of page titles (pagename) user 2 has assigned him/her. column , table names need updated.
pull papers not assigned specific user.
select pagename `page table` id not in (select pageid `assigned table` at.user = 2)
Comments
Post a Comment