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

x
?
Solved

MySQL Grouping syntax

Posted on 2012-08-27
3
Medium Priority
?
428 Views
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!
0
Comment
Question by:erzoolander
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 38337015
select state, count(*) from yourtable group by state
0
 
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

0
 
LVL 2

Author Closing Comment

by:erzoolander
ID: 38337524
Gracias!
0

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