0

I have 2 tables, one called system_dashboard_stats (tbl1) and another called user_dashboard_stats (tbl2). I want to display all rows from tbl1 that dont appear in tbl2.

So far, from looking i've found the below code, however it doesnt seem to be working as I currently see all rows from the DB.

$result11=mysql_query("SELECT * FROM system_dashboard_stats WHERE id NOT IN (SELECT id FROM user_dashboard_stats)")or die('Error' . mysql_error()); 
4
  • show the schema for the two table please Commented Jul 23, 2016 at 19:58
  • See Dangers of NOT In in case it applies Commented Jul 23, 2016 at 20:08
  • update you question and show the table columns name for both the tables Commented Jul 23, 2016 at 20:09
  • See our exciting documentation page here that we so proudly present to everyone ... show create table xyz Commented Jul 23, 2016 at 20:11

2 Answers 2

1

SELECT * FROM system_dashboard_stats LEFT JOIN user_dashboard_stats ON system_dashboard_stats.pk = user_dashboard_stats.fk WHERE user_dashboard_stats.fk IS NULL;

Sign up to request clarification or add additional context in comments.

Comments

0

You should write this

$result11=mysql_query("SELECT * FROM system_dashboard_stats LEFT JOIN user_dashboard_stats ON system_dashboard_stats.pk = user_dashboard_stats.fk WHERE user_dashboard_stats.fk IS NULL")or die('Error' . mysql_error()); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.