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
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.