Jump to content


Photo

join two tables and return missing rows


  • Please log in to reply
2 replies to this topic

#1 nabeel21

nabeel21
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 20 October 2003 - 04:37 PM

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.

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 20 October 2003 - 06:40 PM

SELECT TB1.city FROM TB1 LEFT JOIN TB2 ON TB1.city = TB2.city WHERE TB2.city IS NULL

hth
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 nabeel21

nabeel21
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 24 October 2003 - 12:20 AM

Barand: Thanks alot man... it works perfectly. -- thankssss




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users