Jump to content

Queries between 2 tables..


blackdevil

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/6266-queries-between-2-tables/
Share on other sites

[code]SELECT t1.`Student Metric`
FROM Table1 t1
LEFT 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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.