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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:01:45+00:00 2026-06-17T05:01:45+00:00

Joins are the one thing I could never get my head around, ie, which

  • 0

Joins are the one thing I could never get my head around, ie, which type to use and how they actually work. I need to write a query and I know I will need a join for it.

The database is postgres.

Basic table set up is like this (some details redacted)

rates (
rates_id Primary Key, Auto Increment
state String, can either be 'current' or 'history'
)

rates_records (
rates_records_id Primary key, auto increment
rates_id = integer
column_1,
column_2
)

Every rates_records entry has rates_id set to a value that exists in the rates table

I want to update every rates_records row and modify the column_1 and column_2 data where the associated rates state = 'current'

How would I do this? 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-17T05:01:46+00:00Added an answer on June 17, 2026 at 5:01 am

    An alternative to Stefan’s answer.

    update rates_records 
       set column_1 = 'foo', 
           column_2 = 'bar'
    from rates 
      where rates.rates_id = rates_records.rates_id
        and rates.state = 'current';
    

    More details and examples are in the manul: http://www.postgresql.org/docs/current/static/sql-update.html

    Which format you prefer is basically a matter of taste. I don’t believe one is better or faster than the other (Stefan’s answer being standard SQL so it’s portable across DBMS).

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

Sidebar

Related Questions

which one run faster in mysql: a query with multiple joins or that query
I have two tables, which I need to join by one column and is
Let's assume one joins a project near the end of its development cycle. The
I've been working on some MySQL Joins but this one has got me a
Left outer joins should return at least one row from the T1 table if
which one is faster select * from parents p inner join children c on
I could test upload of one file attach_file 'photo', File.join(Rails.root, 'public', 'uploads', 'test.png') But
i never use Dependency Injection in apps. i go through few article with Dependency
How could I join 2 or more zend applications inside another one? In other
I am defining an entity, myParent, it works fine except for one thing. 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.