Jump to content

Join Two Tables


nabeel21

Recommended Posts

I took this right out of the MySQL Manual. Hope it helps.

 

If there is no matching record for the right table in the ON or USING part in a LEFT JOIN, a row with all columns set to NULL is used for the right table. You can use this fact to find records in a table that have no counterpart in another table:

 

mysql> select table1.* from table1

          LEFT JOIN table2 ON table1.id=table2.id

          where table2.id is NULL;

 

This example finds all rows in table1 with an id value that is not present in table2 (that is, all rows in table1 with no corresponding row in table2). This assumes that table2.id is declared NOT NULL, of course. See section 12.5.5 How MySQL Optimizes LEFT JOIN and RIGHT JOIN.

Link to comment
Share on other sites

Here are 2 tables which share the same columns (CITY and COUNTY)

 

TB1 (Main table that stores the info of all cities and counties)

 

CITY-------------------------COUNTY

---------------------------------------

Tampa----------------------Hillsborough

Orlando---------------------Orange

Frostproof-------------------Polk

Arcadia----------------------Desoto

County----------------------Collier

Tallahassee-----------------Leon

----------------------------------------------

 

TB2 (Contains info for all cities and counties who have submitted data)

 

CITY--------------------------COUNTY

---------------------------------------

Arcadia----------------------Desoto

County----------------------Collier

Tallahassee-----------------Leon

------------------------------------------------

 

Now I want to query TB1 and find out which city/county has NOT submitted their data.

 

The query should return

 

CITY-------------------------COUNTY

----------------------------------------

Tampa----------------------Hillsborough

Orlando---------------------Orange

Frostproof------------------Polk

 

 

Thanks in advance.

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.