简体   繁体   中英

Self Join in MS access returns too many record

I have a table in 2013 MS acces s that has civilian names with the fields : First_Name (text), Last_name(text), ID_no(primary key), Gender(text), Continent(text)(as in the continent they live in), Sector_area(text).

the table is called People. to self join it so that people who are in the same continent pop up I was taught to say,

SELECT A.First_Name AS Name1, B.First_Name AS Name2, A.Continent
FROM People AS A, People AS B
WHERE A.ID_No <> B.ID_No
AND A.Continent = B.Continent
ORDER BY A.Continent;

the table only has 70 records but when the sql is run i get 760 records. the script creates a list of combinations of names as Name1 and Name2.

How do I stop this combination making and only getting less records?

Self join is not the solution. GROUP By should be.

select FirstName, LastName, Continent from
People
group by FirstName, LastName, Continent
order by Continent, LastName

or

select FirstName, LastName from
People
where Continent = 'Africa'
group by FirstName, LastName
order by LastName

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM