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

  • SEARCH
  • Home
  • 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 7053485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:30:39+00:00 2026-05-28T03:30:39+00:00

I would like to create a field in my sql query based on the

  • 0

I would like to create a field in my sql query based on the data in another field. For example:

First Name  Last Name  Hometown      State (created column based on Hometown)
Phil        Smith      Brooklyn      NY
Bill        Jones      Manhattan     NY
Abraham     Phillips   Cleveland     OH
Michael     Davis      Cincinnati    OH
William     Brett      Queens        NY

The “State” column could come from a look-up table or in an if / else statement. I’m not sure how to do this, so I would appreciate any help.

  • 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-05-28T03:30:40+00:00Added an answer on May 28, 2026 at 3:30 am

    This is one “solution”, there are many more.

    You could create one table called “Person” consisting of FirstName, LastName and Hometown (I presume you may have that table already) and a lookup table called “CityToState” with City and State.

    Fill the lookup table with appropriate data (it’ll be quite large, I’m sure) and issue the query

    select FirstName, LastName, Hometown, State 
        from Person left join CityToState on Hometown=City;
    

    That should give you the correct data, with NULL returned for the state if the city does not exist in the lookup table.

    Basically what this does is to get all data from Person and join it, row by row with the row in CityToState where HomeTown is the same as City. The “left” part means that it should return the row from the left table (Person) even if there is no matching row in CityToState.

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

Sidebar

Related Questions

I'm attempting to create a T-SQL case statement to filter a query based on
I would like to create a stored procedure with parameters that indicate which fields
I have a 'created_date' DATETIME field which I would like to be populated with
i would like create a array of structure which have a dynamic array :
I would like to create this shape using just css. I am pretty sure
I would like to create a c++ type that mimic the build-in type exactly.
I would like to create a json object to send as a post array,
I would like to create set of strings and below is the only limitation.
I would like to create a class that runs something (a runnable) at regular
I would like to create a virtual host in apache2, but I want it

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.