SELECT DISTINCT

  • Thread starter Thread starter D.Logue
  • Start date Start date
D

D.Logue

SELECT DISTINCT [Last Name], [First Name], b.City
FROM Staff, Branch AS b;


Distinct has no effect for me, I get multiple names etc?.
 
D.Logue said:
SELECT DISTINCT [Last Name], [First Name], b.City
FROM Staff, Branch AS b;


Distinct has no effect for me, I get multiple names etc?.

You've posted this before. Your query has no join(s). That causes a Cartesian
product where every row in the first table is repeated for every row in the
second table. DISTINCT will not help that. You need to add a join on the filed
or fields that the tables have in common.
 
SELECT DISTINCT [Last Name], [First Name], b.City
FROM Staff, Branch AS b;


Distinct has no effect for me, I get multiple names etc?.

Which table has [Last Name] and [First Name] in it - Staff I presume?
Is there any relationship between the Staff and Branch tables? As
written this will pair every single record in Staff, no matter what
branch the person works at, with every single record in Branch: this
will give you as many duplicates of each name as there are different
branches.
 
There is a relationship between Branch and Staff
Branch Number is in both tables and are linked.

SELECT DISTINCT [Last Name], [First Name], b.City
FROM Staff, Branch AS b;


Distinct has no effect for me, I get multiple names etc?.

Which table has [Last Name] and [First Name] in it - Staff I presume?
Is there any relationship between the Staff and Branch tables? As
written this will pair every single record in Staff, no matter what
branch the person works at, with every single record in Branch: this
will give you as many duplicates of each name as there are different
branches.
 
There is a relationship between Branch and Staff
Branch Number is in both tables and are linked.

Then include that Join in your query:

SELECT DISTINCT [Last Name], [First Name], b.City
FROM Staff INNER JOIN Branch AS b
ON Branch.[Branch Number] = Staff.[Branch Number];
 
Back
Top