[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


MySQL Grouping syntax

Posted on 2012-08-27
Medium Priority
Last Modified: 2012-08-27
Hi -

I've got about 3000 entries in my table...various addresses (city, state, zip, etc).  However, only about 30 of the 50 states are represented in the table.

What would the MySQL syntax be to get a simple list (CA, FL, IO, WA...etc) of the states represented in the table?

Thanks in advance!
Question by:erzoolander
LVL 143

Accepted Solution

Guy Hengel [angelIII / a3] earned 2000 total points
ID: 38337015
select state, count(*) from yourtable group by state
LVL 60

Expert Comment

by:Julian Hansen
ID: 38337461
AngelIII's code will give you the same results with the number rows for each state.
If you just want the list of states in the database you can use this query
SELECT DISTINCT state FROM yourtable

Open in new window


Author Closing Comment

ID: 38337524

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month19 days, 11 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question