Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8436645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:14:12+00:00 2026-06-10T07:14:12+00:00

I have three columns in a table Id, State, City. Each state contains dozens

  • 0

I have three columns in a table Id, State, City. Each state contains dozens of cities. all I want to do is select unique states and get their Id.

SELECT DISTINCT(State) FROM LocationTable;

This works perfectly, but I need to get Id too. I tried:

SELECT DISTINCT(State), Id FROM LocationTable 

And

SELECT State, Id FROM LocationTable GROUP BY State, Id

But it still doesn’t return unique states.. Basically I need to get this MySQL query running on MSSQL:

SELECT UNIQUE(State), Id FROM LocationTable;

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:14:14+00:00Added an answer on June 10, 2026 at 7:14 am
    SELECT State, Id FROM LocationTable GROUP BY State, Id 
    

    What do you expect it to do when it finds 2 states that match, but have different IDs? It would return the state twice, once per ID.

    I suspect your data is something like this:

     ID, State, City
      1   WA    Seattle
      2   WA    Tacoma
    

    When you say you want the ID for the state, you are going to have to make a choice about which ID would would want, max, min, etc. There is no single ID for the state.

    Response to comment : It could be something like…

    Select max(cast(id as binary(16)), state from locationtable group by state
    

    But I think the validity of the ID is really in question here, what are you going to do with the ID, it will be for 1 row only, not all rows for that state. (Cast to now deal with the fact its a uniqueidentifier field)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table column where each row has one of three states, and
I have a table with three columns, and two cells contain select boxes with
I have a table with the following columns, City, State, Zip, and Zone. I
I have mysql table tmp with columns pid,city,state,country. I write queries so i can
I have the following database tables: table: person Columns: id, first_name, age, city, state
I have three columns in mysql table: tax_id, company_name, store_name. I need that tax_id
Consider i have a user table and I have three columns mobilePhone , homePhone
I have three tables, Name - columns Custpackingslipjour(table 1) - (deliverydate, dateclosed,, salesid) Inventrans
I have a table in HTML which has three columns i.e Error - User
I have a table of users with three columns. Username Accepted Rejected User 1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.