Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
gtFlue
Starting Member
8 Posts |
Posted - 2012-01-27 : 11:55:54
|
| Relatively new to SQL (taken a handful of classes) but I'm having a rough time with Joins.If I'm joining two tables, one has 15 of the same cog (for lack of a better term) and the other has 40 sprockets. how do I prevent the join from returning 600 rows if I'm limited on the number of conditions that are true in both tables?I understand the more join conditions you are able to set the more unique rows are returned, but what do you do if you have only 1 or 2 available join conditions?Even using distinct does not reduce the number by much.Thanks. |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2012-01-27 : 12:01:03
|
| It would be easier if you posted your table structures. You will have key fields between the tables which must match when you write the join condition, this should limit what is joined to what.Then you limit further on your where clause to get only the results returned that match a condition.Anyway, post your structures and a bit of sample data and the expected result set and you will get better answers that might start to make sense. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
gtFlue
Starting Member
8 Posts |
Posted - 2012-01-27 : 13:08:16
|
| um.... table 1 has 81 columns (2 primary Keys), Table 2 has 29 columns (3 primary Keys) only 1 PK is shared between the two. VisitID.all columns are Varchar, except for the 2 date columns. Other than the single PK only one other column is shard and that is a name column.I am also only reporting on 4 fields.Would maybe a subquery be my best bet, use the smaller table to return only distinct rows based on the Name field, and then pull out the required fields from the other table?These tables are huge since they're in a Med database. I'm trying to report insurance expiration dates for patients...easier said than done when there are more than 500K patients in the database...uhg. |
 |
|
|
|
|
|