Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 24-03-2009
Member
 
Join Date: Feb 2009
Posts: 38
Too many rows after Join in SQL

When I perform join operation on two tables, I get too many rows than actually it should appear.
How do I fix it ?
If anyone knows any solution or alternative to this.... then please suggest.
Reply With Quote
  #2  
Old 24-03-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: Too many rows after Join in SQL

When you join tables, make sure that the number of join predicates in the search condition is one less than the number of tables in the from list. Otherwise, you will get many more rows returned than you probably intended.
Reply With Quote
  #3  
Old 24-03-2009
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: Too many rows after Join in SQL

The problem you are facing(extra rows) is called a Cartesian product.
You basically asked for a combination of every value from one table matched to every value from the other table. In your case you did have an "except"-type condition so you eliminated a few of the matches.

Let me explain it this way:
Imagine you have two identical lists of names.
Each list is 200 names long and there are no duplicates within the list.
The query you just wrote would combine each of the first 200 names with
each one of the other 199 names from the other table that didn't match so
that your final results would be (200x199) or 39800 records, way more than
the 400 you started with.....
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Too many rows after Join in SQL"
Thread Thread Starter Forum Replies Last Post
Can?t join friends in Max Payne 3, error "Join Failed Failure: Blacklisted. G.Kahli Video Games 3 02-06-2012 12:44 PM
Replace Duplicate Rows ajk79 Windows Software 1 20-07-2010 11:01 AM
How to Insert Multiple Rows At Once in PHP Zeverto Software Development 3 22-09-2009 03:30 PM
Merging duplicate names not rows copy rows into new workbook each time VBA Excel 2003 awkwardsmile Software Development 2 09-07-2009 08:57 AM
Equi Join vs Natural Join in SQL Demetrius Software Development 3 14-05-2009 12:55 PM


All times are GMT +5.5. The time now is 06:56 PM.