SQL Basics

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized ForumsDatabasesSQL Basics

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old July 5th, 2017, 10:23 AM
lukael82 lukael82 is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Jul 2017
Posts: 0 lukael82 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 34 m 11 sec
Reputation Power: 0
Select distinct records with JOIN

Hello everyone,

can somebody explain me this - let's say I have 3 tables:

Code:
PERSON:
ID1
Name

ADDRESS:
ID1_FK
Street_Address

OWNEDCARS:
ID1_FK
Car_model


Now let's say 1 person has 2 addresses and 2 owned cars. And when I do JOIN over all for specific record like this:

Code:
SELECT  Name,  Street_Address,  Car_Model FROM Person 
     LEFT JOIN ADDRESS ON  PERSON.ID=ADDRESS.ID_FK
     LEFT JOIN OWNEDCARS ON PERSON.ID=OWNDECARS.ID_FK
     WHERE PERSON.ID='6';


I get a result like this:
Code:
Mike, 4th avenue
Mike, 2nd avenue
Mike, BMW
Mike,BMW
Mike,Mercedes
Mike,Mercedes


As you notice, cars that were returned are doubled - what is happening here ? Why is JOIN returning correct number of addresess but not cars ?

What I want is to get Distinct records from all joined table which regards to certain record.

P.S: notice that I have same name for ID's in "Address" and "OwnedCars" table, which is "ID1_FK". That is my actual design, so I'm afraid that It has to do something with name conflicts.

Any advice appreciated, I'm quite a rooky when It comes to SQL.

Reply With Quote
Reply

Viewing: Tutorialized ForumsDatabasesSQL Basics > Select distinct records with JOIN


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap