tags:

views:

150

answers:

3

Person Table

ID FirstName  LastName PersonalWealth
1  Hello      Alest    $10,000.00
2  Leeds      United   $20,000.00
3  Middle     Brough   $30,000.00
4  Arsenal    Chelsey  $40,000.00
5  Manchester United   $50,000.00
6  Peter      Mean     $60,000.00
7  Hello      Coward   $60,000.00

Car Table

ID  CarRego  Model   Make   Manufacture  Year PersonID
1   abc123   Van            Toyota       2001 1
2   abc234   Ute            Honda        2005 1
3   pio345   Hatchback      Mitsubishi   1990 2
4   elf234   Hatchback      Ford         1996 3
5   flo124   Hatchback      Toyota       1992 4
6   asc234   hatchback      Holden       1965 6
7   xyz      hatchback      Holden       1998 5
8   avc      Van            jhjhjkhk     1989 1 

Here is the SQL code that i have

SELECT
  Count(Car.ID) AS CountOfid1, 
  Car.Model
FROM person
INNER JOIN Car ON person.ID=Car.ID
GROUP BY Car.Model; 

But it works with van saying 2 of them but in real there is only one owner how do i fix this?

Help would be much appreciated

+1  A: 

Youl have to be a little more clear in your question ,im not sure what you want to achieve! if there is one owner per car then maybe setting the PK of car to owner then you ensure only own owner/car. That way you will never have dupe owners cos the pk will clash and youl get a PK exception if you try to add.

Chris
here is the database for car ID CarRego Model Make ManufactureYear PersonID1 abc123 Van Toyota 2001 12 abc234 Ute Honda 2005 13 pio345 HatchbackMitsubishi1990 24 elf234 HatchbackFord 1996 35 flo124 HatchbackToyota 1992 46 asc234 hatchbackHolden 1965 67 xyz hatchbackHolden 1998 58 avc Van jhjhjkhk 1989 1
roller
+1  A: 

I am having a lot of trouble following this question but i see one clear problem

INNER JOIN Car ON person.ID=Car.ID

This does not make sense to me. I think what that line should read is

INNER JOIN Car ON person.ID=Car.OwnerID

Comparing primary keys to primary keys means nothing

Andrey
A: 

here is the database for car

ID  CarRego  Model   Make   Manufacture  Year PersonID
1   abc123   Van            Toyota       2001 1
2   abc234   Ute            Honda        2005 1
3   pio345   Hatchback      Mitsubishi   1990 2
4   elf234   Hatchback      Ford         1996 3
5   flo124   Hatchback      Toyota       1992 4
6   asc234   hatchback      Holden       1965 6
7   xyz      hatchback      Holden       1998 5
8   avc      Van            jhjhjkhk     1989 1 
roller
iam trying to find out count of owners of each model of car so doing the count let's say van has one owner so the sql should return 1 but its returning two different person. make and model is different
roller