blackdevil Posted March 31, 2006 Share Posted March 31, 2006 HI all.I am currently designing MysQL database and facing few problem about queries.Here it goes. I have 2 table: table 1 (consists of 2 fields:Student Metric and Course Id) and table 2 (consists of 4 fields: Student Metric, Class Id, Date, Time). Now I need to list a query between the 2 tables that lists the Student metric fields which contained in table 1 but not contained in the table 2. How can I do that in PHP code communicating with MySQL database?Thanks for any help in advance..Cheers Quote Link to comment Share on other sites More sharing options...
jvrothjr Posted March 31, 2006 Share Posted March 31, 2006 [code]$query = ("SELECT Table1.Student Metric FROM Table1 INNER JOIN Table2 ON Table1.Student Metric = Table2.Student Metric");[/code] Quote Link to comment Share on other sites More sharing options...
Barand Posted March 31, 2006 Share Posted March 31, 2006 [code]SELECT t1.`Student Metric`FROM Table1 t1LEFT JOIN Table2 t2 ON t1.`Student Metric` = t2.`Student Metric`WHERE t2.`Student Metric` IS NULL[/code]You need LEFT JOIN to find unmatched records. NULL values are returned from the right table (in this case Table2) if there is no match.PS Avoid column and table names containing spaces Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.