Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Distinct alternative

Status
Not open for further replies.

manicleek

Technical User
Jun 16, 2004
143
GB
I am trying to query a DB by town name

I want it to redirect to a certain page if there is more than one town with that name

e.g.

Birmingham, England
Birmingham, USA

but I'm unsure what SQL to use.

I can't use SELECT DISTINCT as they are both the same town name it will just return 1
 
You can use the GROUP BY clause in your query. Something like this :

Code:
SELECT townName
FROM yourTable
GROUP BY townName HAVING COUNT(*) > 1
 
You can use something like this

CountValue = "Select Count(townName) as TownCount from yourTable Group By townName"

Later on in your program you can say if CountValue > 1 then go to page X else go to page Y
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top