I have a query that picks the lowest total by using a Group By clause. But if there are two lowest totals of the same amount I only want my query to return one value.
Any ideas?
Thanks
Any ideas?
Thanks
SELECT Val(Mid(Min(Format(tbl.Popn, '0000000000') & tbl.ID), 11)) AS ID, _
Mid(Min(Format(tbl.Popn, '0000000000') & tbl.Country), 11) AS Country, _
Min(tbl.Popn) AS Popn
FROM [YourTable] AS tbl
ID; Long; PK Country: Text; Population: Long; Continent: Text;
ID Country Population Continent 1 France 60 Europe 2 USA 200 North America 3 UK 60 Europe 4 Four 100 Europe 5 Canada 100 North America 6 Elsewhere 1000 Asia 7 Another 1000 Asia 8 And Another 2000 Asia 9 Finally 80 Europe
min ID LowestPopulation Continent 6 1000 Asia 1 60 Europe 2 100 North America
ID Country Population Continent 6 Elsewhere 1000 Asia 1 France 60 Europe 2 USA 200 North America
Min Country continent 6 Asia 1 Europe 5 North America
ID Country Population continent 6 Elsewhere 1000 Asia 1 France 60 Europe 5 Canada 100 North America
SELECT Country FROM table WHERE Popn = Min(Popn)
ID Country Population Continent 1 France 60 Europe 2 USA 200 North America 3 UK 60 Europe 4 Germany 100 Europe 5 Canada 100 North America 6 India 1,000 Asia 7 Pakistan 1,000 Asia 8 China 2,000 Asia 9 Luxembourg 80 Europe
SELECT [Continent],
Table.ID
[Country],
[Population],
FROM Table INNER JOIN
(SELECT Val(Mid(Min(Format([Population], '0000000000') &
Table.ID), 11)) AS ID
FROM [Table]
GROUP BY [Continent]) AS sub
ON Table.ID = sub.ID
ORDER BY [Continent]
Continent ID Country Population Asia 6 India 1,000 Europe 1 France 60 North America 5 Canada 100
Comment