MySQL Grouping syntax

Posted on 2012-08-27
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 142

    Accepted Solution

    select state, count(*) from yourtable group by state
    LVL 49

    Expert Comment

    by:Julian Hansen
    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

    LVL 1

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Suggested Solutions

    Title # Comments Views Activity
    Reverse asset logic not working 11 26
    SQL Insert Query Help, part2 6 28
    When and why to use Json with PHP 10 23
    Php Sql Query 7 19
    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now