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 9190103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:23:07+00:00 2026-06-17T20:23:07+00:00

Imagine that you have a table like this: +————-+——————+——+—–+———+—————-+ | Field | Type |

  • 0

Imagine that you have a table like this:

+-------------+------------------+------+-----+---------+----------------+
| Field       | Type             | Null | Key | Default | Extra          |
+-------------+------------------+------+-----+---------+----------------+
| id          | int(11)          | NO   | PRI | NULL    | auto_increment |
| name        | varchar(255)     | NO   |     |         |                |
| parent_id   | int(11)          | YES  | MUL | NULL    |                |
+-------------+------------------+------+-----+---------+----------------+

Let’s call this table locations

This represents a city or a state.

For example if name field is Los Angeles, its parent_id would represent a row with a name fieldCalifornia.

Now imagine that you have another table like this:

+-----------------+---------------+------+-----+---------+----------------+
| Field           | Type          | Null | Key | Default | Extra          |
+-----------------+---------------+------+-----+---------+----------------+
| id              | int(11)       | NO   | PRI | NULL    | auto_increment |
| name            | varchar(450)  | YES  |     | NULL    |                |
| state           | varchar(135)  | YES  |     | NULL    |                |
+-----------------+---------------+------+-----+---------+----------------+

Let’s call this table cities.

Each row represents a city, and the id field matches the idin the locationstable.

In this table the state field is always empty, so I would like to update it with the name field from the locations table.

I’ve tried this query in order to get the state value, but it doesn’t seem to work (it takes a long time and nothing happens):

SELECT name FROM locations WHERE id IN 
(SELECT parent_gid FROM locations INNER JOIN cities  
ON locations.id = cities.id);

Any suggestions on how to achieve this?

  • 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-17T20:23:08+00:00Added an answer on June 17, 2026 at 8:23 pm

    if only only want SELECT statement, use JOIN

    SELECT  a.id, a.name, b.name As State
    FROM    cities a
            INNER JOIN locations b
                ON a.id = b.id
    

    but if you want to update the table,

    UPDATE  cities a
            INNER JOIN locations b
                On a.ID = b.ID
    SET     a.State = b.name
    

    UPDATE

    SELECT  a.id, a.name, c.name As State
    FROM    cities a
            INNER JOIN locations b
                ON a.id = b.id
            LEFT JOIN locations c
                On b.parent_ID = c.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table cell of type nvarchar(max) that typically looks like this: A03
Imagine an account table that looks like this: Column | Type | Modifiers ------------+-----------------------------+-----------
let's imagine that i have a simple table like this: id - record id
Imagine I have a column of a table like this: b - 1 1
I have a table in SQL Server 2008 that looks kind of like this:
Lets say I have a session table like this: [Session] ------- Id: int UserId:
Imagine I have a service that looks like this: public interface MyAccountService { boolean
Let me explain this a bit. Imagine I have a table like this: id
I have a table like this: CREATE TABLE records (_id INTEGER PRIMARY KEY, question
hi there imagine I have a table like this Id | Name | City

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.