|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Join Help
I have three tables I need to get the data from.
Table a : General Info of a person Table b: Addres of each person in table a (a person can have multiple addresses) Table c: Mapping of zip code to county I need to query the database such that, I get the columns from table a, columns of table b and county from table c. This is the query I use, I am getting multiple/duplicate rows. Any comments ? ----------------------------------------------------------- SELECT a.peopleID, a.FirstNAME, a.MiddleNAME, a.LastNAME, a.DOB, c.HouseNumber as HOUSE_NUMBER, c.Street as STREET, c.ApartmentNum as APARTMENT_NUMBER, c.CITY, c.STATE, c.Zip as ZIP_CODE from TU_People a INNER JOIN TU_Address c ON a.peopleID = c.peopleID LEFT JOIN zipcodes zip on c.zip = zip.zipcode where a.peopleID =1 ----------------------------------------------------------- |
|
#2
|
||||
|
||||
|
You're joining the zipcode table but you're not using any fields from it in your query. Intentional? If so, then you can just exclude it and you'd probably solve your problem.
Otherwise, post your tables design (field names). Also, have you tried changing the LEFT JOIN to an INNER JOIN? |
|
#3
|
|||
|
|||
|
Oh, I am sorry. Here is the corrected query.
Code:
SELECT a.peopleID, a.FirstNAME, a.MiddleNAME, a.LastNAME, a.DOB, c.HouseNumber as HOUSE_NUMBER, c.Street as STREET, c.ApartmentNum as APARTMENT_NUMBER, c.CITY, c.STATE, c.Zip as ZIP_CODE, zip.county as COUNTY from TU_People a INNER JOIN TU_Address c ON a.peopleID = c.peopleID LEFT JOIN zipcodes zip on c.zip = zip.zipcode where a.peopleID =1 Quote:
|
|
#4
|
|||
|
|||
|
Yes, and I tried changing it to INNER JOIN. Still does not work
Quote:
|
|
#5
|
||||
|
||||
|
i doubt very much that you are getting duplicate rows, i.e. duplicate in all columns
your query is fine there must be something wrong with the data please show a few rows from each table that illustrate the problem you're having |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Join Help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|